• poj1654 Area


    题目描述:

    vjudge

    POJ

    题解:

    本以为是水题结果是神题

    计算几何求多边形面积。

    考虑到结果一定是整数或者整数/2,我们应该用long long 来存……

    用double会死……

    还有日常只能用c++编译器,不能用g++。

    还有用abs会莫名ce,要手写。

    代码:

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    struct Point
    {
        ll x,y;
        Point(){}
        Point(ll x,ll y):x(x),y(y){}
        Point operator + (const Point&a)const{return Point(x+a.x,y+a.y);}
        Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
        ll operator ^ (const Point&a)const{return x*a.y-y*a.x;}
    }p[10];
    typedef Point Vector;
    int T;
    char ch[1000050];
    void init()
    {
        p[1] = Point(-1,-1),p[2] = Point(0,-1),p[3] = Point(1,-1),p[4] = Point(-1,0);
        p[6] = Point(1,0),p[7] = Point(-1,1),p[8] = Point(0,1),p[9] = Point(1,1);
    }
    void work()
    {
        scanf("%s",ch+1);
        Point s0(0,0),s1(0,0),s2(0,0);
        int len = strlen(ch+1);
        long long ans = 0;
        for(int i=1;i<len;i++)
        {
            s1 = s2,s2 = s2+p[ch[i]-'0'];
            ans+=((s1-s0)^(s2-s0));
        }
        if(ans<0)ans=-ans;
        if(ans&1)
        {
            printf("%lld.5
    ",ans/2);
        }else
        {
            printf("%lld
    ",ans/2);
        }
    }
    int main()
    {
        scanf("%d",&T);init();
        while(T--)work();
        return 0;
    }
    View Code
  • 相关阅读:
    YAOI Summer Round #4 (Div.2) 题解
    2021 暑假集训(福建师大附中)
    YAOI Round #7 题解
    YAOI Round #5 题解
    插头DP
    四边形不等式
    YAOI Round #3 题解
    关于 2020 年
    图论相关性质和结论(基础)
    斜率优化 DP :Luogu P2365 P5785「SDOI2012」任务安排 & 弱化版
  • 原文地址:https://www.cnblogs.com/LiGuanlin1124/p/10983095.html
Copyright © 2020-2023  润新知