poj 1656 Counting Black

来源:互联网 发布:解放军报网络图片赵阳 编辑:程序博客网 时间:2024/04/24 08:48
这个本来应该是不水的,估计题意原来是让用线段树或者树状数组做的,但是,题目里的数据规模太小了,直接模拟就过了。。也就成超级水题了。
#include <stdio.h>#include <string.h>int map[103][103];//在外部定义自动初始化为0int 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;}


原创粉丝点击