poj 1656 Counting Black
这个本来应该是不水的,估计题意原来是让用线段树或者树状数组做的,但是,题目里的数据规模太小了,直接模拟就过了。。也就成超级水题了。
#include <stdio.h> #include <string.h> int map[103][103]; //在外部定义自动初始化为0 int main() { int n; scanf("%d",&n); char input[10]; //黑、白、测试 int x,y,L; //边界界定值 int i,j; int count; //黑色方块的计算器 while(n--) { scanf("%s",input); scanf("%d%d%d",&x,&y,&L); //printf("输出:%s %d %d %d\n\n",input,x,y,L); // Paint a white square on the board, // the square is defined by left-top grid (x, y) // and right-bottom grid (x+L-1, y+L-1) if(strcmp(input,"BLACK")==0) { for(i=x;i<=x+L-1;i++) for(j=y;j<=y+L-1;j++) map[i][j]=1; } if(strcmp(input,"WHITE")==0) { for(i=x;i<=x+L-1;i++) for(j=y;j<=y+L-1;j++) map[i][j]=0; } // Ask for the number of black grids // in the square (x, y)- (x+L-1, y+L-1) count=0; if(strcmp(input,"TEST")==0) { for(i=x;i<=x+L-1;i++) for(j=y;j<=y+L-1;j++) { if(map[i][j]==1) count++; } printf("%d\n",count); } } return 0; }
最后更新:2017-04-03 14:53:41