这道题目可以纯暴力:
#include<bits/stdc++.h> //Minecraft 666 using namespace std; int a[110][110]; int n,m,k,ans; int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); a[x-2][y]=1;a[x-1][y]=1;a[x][y]=1;a[x+1][y]=1;a[x-1][y-1]=1;a[x+1][y-1]=1; a[x+2][y]=1;a[x][y+2]=1;a[x][y+1]=1;a[x][y-1]=1;a[x][y-2]=1;a[x+1][y+1]=1;a[x-1][y+1]=1; } for(int i=1;i<=k;i++){ int x,y; scanf("%d%d",&x,&y); a[x-2][y-2]=1;a[x-1][y-2]=1;a[x][y-2]=1;a[x+1][y-2]=1;a[x+2][y-2]=1; a[x-2][y-1]=1;a[x-1][y-1]=1;a[x][y-1]=1;a[x+1][y-1]=1;a[x+2][y-1]=1; a[x-2][y]=1;a[x-1][y]=1;a[x][y]=1;a[x+1][y]=1;a[x+2][y]=1; a[x-2][y+1]=1;a[x-1][y+1]=1;a[x][y+1]=1;a[x+1][y+1]=1;a[x+2][y+1]=1; a[x-2][y+2]=1;a[x-1][y+2]=1;a[x][y+2]=1;a[x+1][y+2]=1;a[x+2][y+2]=1; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]==0) ans++; printf("%d\n",ans); return 0; }
原文地址:https://www.cnblogs.com/yzx1798106406/p/8964559.html
时间: 2024-10-06 15:10:59