poj 1656 Counting Black

简介:
这个本来应该是不水的,估计题意原来是让用线段树或者树状数组做的,但是,题目里的数据规模太小了,直接模拟就过了。。也就成超级水题了。
 
 
#include <stdio.h>
#include <string.h>

int map[103][103];		//在外部定义自动初始化为0

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


相关文章
|
4月前
|
人工智能 算法 BI
D - Silver Cow Party——POJ3268(连续用两次Dijkstra算法)
D - Silver Cow Party——POJ3268(连续用两次Dijkstra算法)
|
11月前
light oj 1231-1232 - 1233- Coin Change 背包
暂时到半懂不懂也没办法讲明白,就不误人子弟了,直接贴代码了。
29 0
|
索引
LeetCode 75. Sort Colors
给定一个具有红色,白色或蓝色的n个对象的数组,对它们进行就地排序,使相同颜色的对象相邻,颜色顺序为红色,白色和蓝色。 这里,我们将使用整数0,1和2分别表示红色,白色和蓝色。 注意:您不应该使用库的排序功能来解决此问题。
40 0
LeetCode 75. Sort Colors
|
测试技术
POJ3687---Labeling Balls
POJ3687---Labeling Balls
POJ3687---Labeling Balls
POJ-Silver Cow Party (最短路)
POJ-Silver Cow Party (最短路)
88 0
hdu 1312 Red and Black(BFS)
hdu 1312 Red and Black(BFS)
136 0
|
机器学习/深度学习
HDOJ/HDU 1556 Color the ball(树状数组)
HDOJ/HDU 1556 Color the ball(树状数组)
96 0
HDOJ 1312 (POJ 1979) Red and Black
HDOJ 1312 (POJ 1979) Red and Black
107 0