现在的位置: 首页 > 综合 > 正文

poj 1656 Counting Black

2012年09月23日 ⁄ 综合 ⁄ 共 625字 ⁄ 字号 评论关闭
//简单的模拟题,按部就班地按照题目的意思做就很容易了,给定一定范围,将这范围内的地方涂黑或者涂白,最后统计黑色方格的个数! 
#include <iostream>
#include <string>
using namespace std;

int grid[105][105];

int main()
{
    int i, j, tc, x, y, l, boardx, boardy, ans = 0;
    string str;
    for (i = 1; i <= 100; i++)
       for (j = 1; j <= 100; j++)
            grid[i][j] = 0;
    cin >> tc;
    while (tc--)
    {
          cin >> str >> x >> y >> l;
          boardx = x+l-1;
          boardy = y+l-1;
          if (str == "BLACK")
          {
               for (i = x; i <= boardx; i++)
                  for (j = y; j <= boardy; j++)
                  {
                      if (grid[i][j] == 0)
                          grid[i][j] = 1;
                  }
          }
          else if (str == "WHITE")
          {
               for (i = x; i <= boardx; i++)
                  for (j = y; j <= boardy; j++)
                  {
                      if (grid[i][j] == 1)
                          grid[i][j] = 0;
                  }
          }
          else if (str == "TEST")
          {
               for (i = x; i <= boardx; i++)
                  for (j = y; j <= boardy; j++)
                  {
                      if (grid[i][j] == 1)
                          ans++;
                  }
               cout << ans << endl;
               ans = 0;
          }
    }
    
    system("pause");
} 

抱歉!评论已关闭.