P2956 [USACO09OCT]The Robot Plow G 机器人耕地_i++


P2956 [USACO09OCT]The Robot Plow G 机器人耕地_#include_02

#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main()
{
int x, y, num, x1, y1, x2, y2, cnt = 0;
scanf("%d %d %d", &x, &y, &num);
int sign[x][y], i, j;
for ( i = 0; i < x; i++)
for ( j = 0; j < y; j++)
sign[i][j] = 0;
while(num){
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
for ( i = x1 - 1; i <= x2 - 1; i++)
for ( j = y1 - 1; j <= y2 - 1; j++)
sign[i][j] = 1;
num--;
}
for (i = 0; i < x; i++)
for ( j = 0; j < y; j++){
if ( sign[i][j] == 1)
cnt++;
}
printf("%d", cnt);
return 0;
}

也就是标记数组做标记,只不过成了二维数组。