代码:
#include<stdio.h> struct huobaye{ int x; int y; }; struct stoneye{ int x; int y; }; int abs(int n) { int flag; if(n>=0) flag=n; else flag = -1*n; return flag; } int main() { int i,j,n,m,k; scanf("%d%d%d",&n,&m,&k); //25 5 struct huobaye huoba[25]; struct stoneye stone[5]; //int a,b; for(i=1;i<=m;i++) { scanf("%d%d",&huoba[i].x,&huoba[i].y); } if(k>=1) { for(i=1;i<=k;i++) { scanf("%d%d",&stone[i].x,&stone[i].y); } } int location[101][101]={0}; int dx[] = {-2,-1,1,2}; int dy[] = {2,1,-1,-2}; int dz[]={-1,1,1,1,-1,-1,1,-1}; int djs; int q,p; for(i=1;i<=m;i++) { q = huoba[i].x; p = huoba[i].y; djs=1; while(djs) { for(j=0;j<4;j++) { if(p+dx[j]>0 && p+dx[j]<=n) { location[q][p+dx[j]]=1; } if(q+dy[j]>0 && q+dy[j]<=n) { location[q+dy[j]][p]=1; } } for(j=0;j<8;) { if((q+dz[j]>0&&q+dz[j]<=n)&&(p+dz[j+1]>0&&p+dz[j+1]<=n)) location[q+dz[j]][p+dz[j+1]]=1; j+=2; } djs--; } location[q][p]=1; } int s,t; if(k>=1) { for(i=1;i<=k;i++) { q = stone[i].x; p = stone[i].y; for(s=1;s<=n;s++) for(t=1;t<=n;t++) { if(abs(s-q)<=2&&abs(t-p)<=2) location[s][t]=1; } location[q][p]=1; } } int count=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(location[i][j]==0) count++; } printf("%d",count); return 0; }
同样使用了位置数组
标签:洛谷,struct,Mc,int,d%,P1789,flag,&&,huobaye From: https://www.cnblogs.com/kmxojer/p/16907268.html