Ziyao has a big drawing board with N * M squares. At the beginning, all the squares on the board are white, represented by the number 0. We can see the 4 * 4 whilte drawing board is:
0000
0000
0000
0000
One day Ziyao wants to draw on the board. He will draw for T times. Each time he will draw a rectangle with the color he like.For each rectangle, we use 4 integers (x1, y1, x2, y2) to express it. It means all squares whose coordinate (x, y) exist both x1 <= x <=x2 and y1 <= y <= y2. If two rectangles are intersected, the intersected part will be covered by the color later drawing.
For example, if he draw a rectangle (1, 2, 3, 3) on the white board with the color ‘1’, the board will be:
0110
0110
0110
0000
And if he go on drawing a rectangle (2, 1, 3, 2) by ‘2’, the board will be:
0110
2210
2210
0000
Now, Ziyao Big God will tell you his drawing process, please tell me how many colors will be there on the board.
#include <stdio.h>
#include <string.h>
int board[100][100];
int main() {
int n, m, t;
scanf("%d%d%d", &n, &m, &t);
memset(board, 0, sizeof(board));
int x1, y1, x2, y2, color;
int i, j;
while (t--) {
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &color);
for (i = x1 - 1; i < x2; i++) {
for (j = y1 - 1; j < y2; j++) {
board[i][j] = color;
}
}
}
int colornum[10];
int h = 0;
int f;
colornum[0] = board[0][0];
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
h++;
for (f = 0; f < h; f++) {
if (colornum[f] == board[i][j]) {
h--;
break;
}
if (f == h - 1) {
colornum[h++] = board[i][j];
}
}
}
}
printf("%d", h + 1);
return 0;
}