閱讀925 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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


最後更新:2017-04-03 14:53:41

  上一篇:go tomcat在開發過程中使用ip地址無法訪問的問題
  下一篇:go 網絡子係統48_ip協議數據幀的發送