zoukankan      html  css  js  c++  java
  • 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;
    }
    这条路我们走的太匆忙~拥抱着并不真实的欲望~
  • 相关阅读:
    ActiveMQ的消息模式——队列模式(Queue)
    在foxmail上添加阿里邮箱
    Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 错误解决
    博客园首页新随笔联系管理订阅订阅随笔- 89 文章- 0 评论- 3 Centos7开放及查看端口
    tomcat设置为开机自启动
    Tensorflow2疑难问题---2、tensorflow2.3的GPU版本安装
    Tensorflow2疑难问题---1、课程介绍
    tensorflow2的gpu的版本安装(一些核心点)
    此环境变量太大, 此对话框允许将值设置为最长2047个字符(解决方法)
    windows下cuda的安装
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2797540.html
Copyright © 2011-2022 走看看