ACdream群赛(4) - D - Draw a Mess

Problem D: Draw a Mess

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 123   Solved: 19
[ Submit][ Status][ Web Board]

Description

It's graduated season, every students should leave something on the wall, so....they draw a lot of geometry shape with different color.
When teacher come to see what happened, without getting angry, he was surprised by the talented achievement made by students. He found the wall full of color have a post-modern style so he want to have an in-depth research on it.
To simplify the problem, we divide the wall into n*m (1 ≤ n, m ≤ 10000) pixels, and we have got the order of coming students who drawing on the wall. We found that all students draw four kinds of geometry shapes in total that is Diamond, Circle, Rectangle and Triangle. Because the students just want to draw a mess, so many shape overlap with each other.
Initially all pixels is white, once a pixel is drawing by someone it will turned to black. 
There are q (1 ≤ q ≤ 100) students who have make a drawing one by one. And after q operation we want to know the amount of black pixels on the wall.

Input

There are multiple test cases.
In the first line of each test case contains three integers n, m, q. The next q lines each line contains a string at first indicating the geometry shape: 
* Circle: given xc, yc, r, and you should cover the pixels(x, y) which satisfied inequality (x - xc)2 + (y - yc)2 ≤ r2; 
* Diamond: given xc, yc, r, and you should cover the pixels(x, y) which satisfied inequality abs(x - xc) + abs(y - yc) ≤ r; 
* Rectangle: given xc, yc, l, w, and you should cover the pixels(x, y) which satisfied xc ≤ x ≤ xc+l-1, yc ≤ y ≤ yc+w-1; 
* Triangle: given xc, yc, w, w is the bottom length and is odd, the pixel(xc, yc) is the middle of the bottom. We define this triangle is isosceles and the height of this triangle is (w+1)/2, you should cover the correspond pixels; 
Note: all shape should not draw out of the n*m wall! You can get more details from the sample and hint. (0 ≤ xc, x ≤ n-1, 0 ≤ yc, y ≤ m-1)

Output

For each test, please output an integer on a single line indicating the answer of the problem.

Sample Input

8 8 4 Diamond 3 3 1 Triangle 4 4 3 Rectangle 1 1 2 2 Circle 6 6 2

Sample Output

23

HINT

The final distribution of the wall:

00000000

03300000

03310000

00111000

00022240

00002444

00004444

00000444

分析:先把每个询问所涉及的行信息都记录下来,之后对于每一行所包含的区间取和

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[1 << 16];
int col[1 << 16];
 
inline int minn(int a, int b) {
    return a < b ? a : b;
}
 
inline int maxx(int a, int b) {
    return a > b ? a : b;
}
 
typedef struct S {
    int left, right;
} OP;
OP op[10010][105];
int n, m, q;
 
bool cmp(OP a, OP b) {
    if (a.left != b.left)
        return a.left < b.left;
    return a.right < b.right;
}
 
void pushup(int rt) {
    sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
 
void pushdown(int rt, int len) {
    if (col[rt]) {
        col[rt << 1] = col[rt << 1 | 1] = col[rt];
        col[rt] = 0;
        sum[rt << 1] = (len - (len >> 1)) * col[rt << 1];
        sum[rt << 1 | 1] = (len >> 1) * col[rt << 1 | 1];
    }
}
 
void build(int l, int r, int rt) {
    if (l == r) {
        sum[rt] = 0;
        return;
    }
    int m = (l + r) >> 1;
    build(lson);
    build(rson);
    pushup(rt);
}
 
void update(int L, int R, int c, int l, int r, int rt) {
    if (L <= l && R >= r) {
        col[rt] = c;
        sum[rt] = c * (r - l + 1);
        return;
    }
    pushdown(rt, r - l + 1);
    int m = (l + r) >> 1;
    if (L <= m)
        update(L, R, c, lson);
    if (R > m)
        update(L, R, c, rson);
    pushup(rt);
}
char type[15];
 
int main() {
    int i, j, xc, yc, l, w, r, zbj, ybj, left, right, end;
    long long ans;
    while (scanf("%d%d%d", &m, &n, &q) != EOF) {
        ans = 0;
        for (i = 0; i < q; ++i)
            for (j = 0; j < m; ++j)
                op[j][i].left = 200000;
        for (i = 0; i < q; ++i) {
            scanf("%s", type);
            if (type[0] == 'R') {
                scanf("%d%d%d%d", &xc, &yc, &l, &w);
                ybj = minn(xc + l - 1, m - 1);
                right = minn(n - 1, yc + w - 1);
                for (j = xc; j <= ybj; ++j) {
                    op[j][i].left = yc;
                    op[j][i].right = right;
                }
            } else {
                scanf("%d%d%d", &xc, &yc, &w);
                if (type[0] == 'C') {
                    zbj = maxx(0, xc - w);
                    for (j = xc; j >= zbj; --j) {
                        r = (int) sqrt(w * w - (j - xc)*(j - xc));
                        op[j][i].left = maxx(0, yc - r);
                        op[j][i].right = minn(yc + r, n - 1);
 
                    }
                    ybj = min(m - 1, xc + w);
                    for (j = min(m - 1, xc + 1); j <= ybj; ++j) {
                        r = (int) sqrt(w * w - (j - xc)*(j - xc));
                        op[j][i].left = maxx(0, yc - r);
                        op[j][i].right = minn(yc + r, n - 1);
 
                    }
                } else if (type[0] == 'D') {
                    zbj = maxx(0, xc - w);
                    for (j = xc; j >= zbj; --j) {
                        r = w + j - xc;
                        op[j][i].left = maxx(0, yc - r);
                        op[j][i].right = minn(yc + r, n - 1);
                        //      printf("SHAN l=%d r=%d\n", op[j][i].left + 1, op[j][i].right + 1);
                    }
                    ybj = minn(m - 1, xc + w);
                    for (j = minn(m - 1, xc + 1); j <= ybj; ++j) {
                        r = xc + w - j;
                        op[j][i].left = maxx(0, yc - r);
                        op[j][i].right = minn(yc + r, n - 1);
                        //     printf("XIAA l=%d r=%d\n", op[j][i].left + 1, op[j][i].right + 1);
                    }
                } else if (type[0] == 'T') {
                    ybj = minn(xc + w / 2, m);
                    for (j = xc; j <= ybj; ++j) {
                        r = xc + w / 2 - j;
                        op[j][i].left = maxx(0, yc - r);
                        op[j][i].right = minn(yc + r, n - 1);
                    }
                }
            }
        }
        for (i = 0; i < m; ++i) {
         //   printf("i=%d :::\n",i);
            sort(op[i], op[i] + q, cmp);
        //     printf("left=%d right=%d\n",op[i][0].left,op[i][0].right);
            if (op[i][0].left > 10000)
                continue;
            ans += op[i][0].right - op[i][0].left + 1;
            end = op[i][0].right;
            for (j = 1; j < q; ++j) {
             //   printf("left=%d right=%d\n",op[i][j].left,op[i][j].right);
                if (op[i][j].left > 10000)
                    break;
                if (op[i][j].right <= end)
                    continue;
                if (op[i][j].left > end) {
                    ans += op[i][j].right - op[i][j].left + 1;
                    end = op[i][j].right;
                } else {
                    ans += op[i][j].right - end;
                    end = op[i][j].right;
                }
            }
        }
        /*
                for (i = 0; i < m; ++i) {
                    //   build(1, n, 1);
                    //     memset(sum, 0, sizeof (sum));
                    //    memset(col, 0, sizeof (col));
                        printf("i=%d\n", i); 
                    for (j = 1; j <= q; ++j) {
                        if (op[j][i].left != -1) {
                                 printf("l=%d r=%d\n", op[j][i].left + 1, op[j][i].right + 1);
                            update(op[j][i].left + 1, op[j][i].right + 1, 1, 1, n, 1);
                        }
                    }
 
                      printf("sum=%d\n", sum[1]);
                    ans += sum[1];
                    update(1, n, 0, 1, n, 1);
                     printf("sum=%d\n", sum[1]);
 
                }
         */
        cout << ans << endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/baidongtan/archive/2012/12/01/2797540.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值