UVALive 5984 Save the Students! (暴力枚举)

题目

UVALive 5984 Save the Students!

题意

给n个图形,有三角形,圆形,正方形,求覆盖了多少个点

解法

暴力枚举

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int area(int x0, int y0, int x1, int y1, int x2, int y2) {
    return abs(x0 * y1 + x2 * y0 + x1 * y2 - x2 * y1 - x0 * y2 - x1 * y0);
}
int vis[200][200];
int main() {
    int T, n;
    int x, y, r, x0, x1, x2, y0, y1, y2, l;
    char op[5];
    scanf("%d", &T);
    while(T--) {
        memset(vis, 0, sizeof(vis));
        int ans = 0;
        scanf("%d", &n);
        for(int ca = 0; ca < n; ca++) {
            scanf("%s", op);
            if(op[0] == 'C') {
                scanf("%d %d %d", &x, &y, &r);
                x += 50; y += 50;
                for(int i = x - r; i <= x + r; i++) {
                    for(int j = y - r; j <= y + r; j++) {
                        if(!vis[i][j] && (i - x) * (i - x) + (j - y) * (j - y) <= r * r) {
                            vis[i][j] = 1;
                            ans ++;
                        }
                    }
                }
            }
            else if(op[0] == 'T') {
                scanf("%d %d %d %d %d %d", &x0, &y0, &x1, &y1, &x2, &y2);
                x0 += 50; y0 += 50; x1 += 50; y1 += 50; x2 += 50; y2 += 50;
                int left = min(min(x0, x1), x2);
                int right = max(max(x0, x1), x2);
                int down = min(min(y0, y1), y2);
                int up = max(max(y0, y1), y2);
                for(int i = left; i <= right; i++) {
                    for(int j = down; j <= up; j++) {
                        if(!vis[i][j] && area(x0, y0, x1, y1, x2, y2) == area(i, j, x1, y1, x2, y2) + area(x0, y0, i, j, x2, y2) + area(x0, y0, x1, y1, i, j)) {
                            vis[i][j] = 1;
                            ans ++;
                        }
                    }
                }
            }
            else if(op[0] == 'S') {
                scanf("%d %d %d", &x, &y, &l);
                x += 50; y += 50;
                for(int i = x; i <= x + l; i++) {
                    for(int j = y; j <= y + l; j++) {
                        if(!vis[i][j] && i >= x && i <= x + l && j >= y && j <= y + l) {
                            vis[i][j] = 1;
                            ans ++;
                        }
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

来源

Regionals 2011 Asia - Amritapuri

赛后总结

2015暑假训练赛个人赛(8.19)

posted @ 2015-08-25 07:16  ACM_Record  阅读(108)  评论(0编辑  收藏  举报