• UVALive 5984


    题目链接:Save the Students!

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    using namespace std;
    
    bool vis[205][205];   // 所有数据保证在1到50.那么坐标在-50到100之间。所以。哈希到50到200之间。开始开的200*200的。WA。
    
    double dis(double x1, double y1, double x2, double y2)  // 两点间距离。
    {
        // cout << x1 << "==" << y1 << "==" << x2<< "==" << y2 << "==" << endl;
        double xx = (x2-x1)*(x2-x1);
        double yy = (y2-y1)*(y2-y1);
        double ans = xx+yy+0.0;
        return ans;
    }
    
    int circle(int a, int b, int r)  //是否在圆内。
    {
        int cnt = 0;
        for (int i=a-r; i<=a+r; ++i)
        {
            for (int j=b-r; j<=b+r; ++j)
            {
                if (!vis[i+100][j+100])
                {
                    if (dis(i, j, a, b) <= r*r)
                    {
                        cnt++;
                        vis[i+100][j+100] = 1;
                    }
                }
            }
        }
        return cnt;
    }
    
    double area(int x1, int y1, int x2, int y2, int x3, int y3) // 三角形面积。
    {
        double temp = (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1);
        temp /= 2.0;
        if (temp < 0) temp = -temp;
        return temp;
    }
    
    int triangle(int x1, int y1, int x2, int y2, int x3, int y3) //是否在三角形内。
    {
        int cnt = 0;
        int minx = min(x1, min(x2, x3));
        int maxx = max(x1, max(x2, x3));
        int miny = min(y1, min(y2, y3));
        int maxy = max(y1, max(y2, y3));
    
        for (int i=minx; i<=maxx; ++i)
        {
            for (int j=miny; j<=maxy; ++j)
            {
                if (!vis[i+100][j+100])
                {
                    double s1 = area(i, j, x1, y1, x2, y2);
                    double s2 = area(i, j, x1, y1, x3, y3);
                    double s3 = area(i, j, x2, y2, x3, y3);
                    double s = area(x1, y1, x2, y2, x3, y3);
                    if (s1 + s2 + s3 == s)
                    {
                        cnt++;
                        vis[i+100][j+100] = 1;
                    }
                }
            }
        }
        return cnt;
    }
    
    int square(int x1, int y1, int l) //正方形直接判断是不是已经被覆盖了。就可以。开始用了一个巨蠢的用距离判断点是不是在正方形内。。呵呵。。。。
    {
        int cnt = 0;
        for (int i=x1; i<=x1+l; ++i)
        {
            for (int j=y1; j<=y1+l; ++j)
            {
                if (!vis[i+100][j+100])
                {
                    cnt++;
                    vis[i+100][j+100] = 1;
                }
            }
        }
        return cnt;
    }
    
    int main()
    {
        int t, n;
        int x1, x2, x3, x4, x5, x6;
        scanf("%d", &t);
        while(t--)
        {
            scanf("%d", &n);
            memset(vis, 0, sizeof(vis));
            int ans = 0;
            for (int i=0; i<n; ++i)
            {
                char temp;
                getchar();
                scanf("%c", &temp);
                if (temp == 'C')
                {
                    scanf("%d%d%d", &x1, &x2, &x3);
                    ans += circle(x1, x2, x3);
                }
                else if (temp == 'S')
                {
                    scanf("%d%d%d", &x1, &x2, &x3);
                    ans += square(x1, x2, x3);
                }
                else if (temp == 'T')
                {
                    scanf("%d%d%d%d%d%d", &x1, &x2, &x3, &x4, &x5, &x6);
                    ans += triangle(x1, x2, x3, x4, x5, x6);
                }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    [三、页面布局]10使用List列表在垂直方向显示一系列的内容
    如何确认11.2 RAC Grid Infrastructure的时区
    节后的人才市场开始活跃了?
    最近看中的几款Limitless的家具
    ORA19808错误一例
    Oracle队列锁: Enqueue HW
    解决Oracle错误ORA15061一例
    Maclean Liu的2011年终总结
    全面掌控!打造智慧城市建设的“领导驾驶舱”
    体验SRCNN和FSRCNN两种图像超分网络应用
  • 原文地址:https://www.cnblogs.com/icode-girl/p/4749117.html
Copyright © 2020-2023  润新知