白色网格统计poj1656-Counting Black
2016-07-31 15:32
453 查看
题意是有一个100x100的网格,然后我们根据指示在网格中涂上白色或者黑色。
然后统计指定网格中白色格子的数量。
#include "stdio.h"
#include "string.h"
void main()
{
int color[105][105];
char s[10];
int n, i, j, x, y, l, sum;
while (scanf("%d", &n) != EOF)
{
memset(color, 0, sizeof(color));
while (n--)
{
scanf("%s %d %d %d", &s, &x, &y, &l);
if (strcmp(s, "BLACK") == 0)
{
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
color[i][j] = 1;
}
else if (strcmp(s, "WHITE") == 0)
{
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
color[i][j] = 0;
}
else
{
sum = 0;
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
if (color[i][j] == 1) sum++;
printf("%d\n", sum);
}
}
}
}
然后统计指定网格中白色格子的数量。
#include "stdio.h"
#include "string.h"
void main()
{
int color[105][105];
char s[10];
int n, i, j, x, y, l, sum;
while (scanf("%d", &n) != EOF)
{
memset(color, 0, sizeof(color));
while (n--)
{
scanf("%s %d %d %d", &s, &x, &y, &l);
if (strcmp(s, "BLACK") == 0)
{
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
color[i][j] = 1;
}
else if (strcmp(s, "WHITE") == 0)
{
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
color[i][j] = 0;
}
else
{
sum = 0;
for (i = x; i < x + l; i++)
for (j = y; j < y + l; j++)
if (color[i][j] == 1) sum++;
printf("%d\n", sum);
}
}
}
}
相关文章推荐
- poj 1656 Counting Black
- POJ 1656 Counting Black(我的水题之路——表格涂色)
- poj 1656 Counting Black
- POJ 1656 Counting Black
- POJ 1656 Counting Black
- poj 1656 Counting Black(模拟)
- poj 1656 Counting Black
- poj 1656 Counting Black
- POJ-1656-Counting Black- 四分树
- poj 1656 Counting Black
- POJ_1656_Counting Black(水题)
- POJ1656 Counting Black [简单暴力]
- Poj 1656 Counting Black
- poj-1656 Counting Black
- POJ 1656 Counting Black
- poj 1656 Counting Black
- poj 1656 Counting Black
- POJ 1656 Counting Black(水~)
- POJ-1656 Counting Black (二维树状数组)
- POJ 1656 Counting Black