color

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值