poj 1656 Counting Black

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;
}




原文地址:https://www.cnblogs.com/gremount/p/5768027.html