100 * 100 格子的白板,左上角坐标为(1, 1),右下角坐标为(100, 100)
对这个白板有3种操作:
对这个白板有3种操作:
WHITE x y L ---- 把左上角坐标为( x, y ),边长为L的区域涂成白色
BLACK x y L ---- 把左上角坐标为( x, y ),边长为L的区域涂成黑色
TEST x y L ---- 统计左上角坐标为( x, y ),边长为L的区域中黑色块的数量
简单的模拟每次操作的过程即可
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 101;
int board[maxn][maxn];
int main()
{
int n;
char op[10];
int x, y, l;
scanf( "%d", &n );
memset( board, 0, sizeof( board ) );
for( int i = 0; i < n; i++ )
{
scanf( "%s%d%d%d", &op, &x, &y, &l );
if( strcmp( op, "BLACK" ) == 0 )
{
for( int j = x; j <= x + l - 1; j++ )
{
for( int k = y; k <= y + l - 1; k++ )
{
board[j][k] = 1;
}
}
}
else if( strcmp( op, "WHITE" ) == 0 )
{
for( int j = x; j <= x + l - 1; j++ )
{
for( int k = y; k <= y + l - 1; k++ )
{
board[j][k] = 0;
}
}
}
else if( strcmp( op, "TEST" ) == 0 )
{
int sum = 0;
for( int j = x; j <= x + l - 1; j++ )
for( int k = y; k <= y + l - 1; k++ )
if( board[j][k] == 1 )
sum++;
printf( "%d\n", sum );
}
}
return 0;
}