poj 1656 Counting Black

来源:互联网 发布:青岛灭门案 知乎 编辑:程序博客网 时间:2024/04/26 00:57

http://poj.org/problem?id=1656

这道题的题目的数据范围是比较小的,所以直接就用暴力处理就可以了,没有必要用二维树状数组,然后要注意的是输入处应该是字符串比较好,因为输入

字符的话(用%s),可能就要处理回车,那样会很麻烦。

#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int a[105][105]={0};int main(){    int x,y,L,T;    char str[10];    scanf("%d",&T);    while(T--)    {       int s=0;       scanf("%s",str);       scanf("%d %d %d",&x,&y,&L);       if(str[0]=='W')         {                          for(int i=x;i<=x+L-1;i++)                for(int j=y;j<=y+L-1;j++)                  {                      a[i][j]=0;                  }         }       else if(str[0]=='B')         {                          for(int i=x;i<=x+L-1;i++)                for(int j=y;j<=y+L-1;j++)                  {                      a[i][j]=1;                  }                       }       else         {                         for(int i=x;i<=x+L-1;i++)                for(int j=y;j<=y+L-1;j++)                  {                      if(a[i][j]==1) s=s+1;                  }             printf("%d\n",s);         }                          }    system("pause");    return 0;}