zoukankan      html  css  js  c++  java
  • poj1654

    题意:计算一个多边形的面积。

    分析:题目中的答案要么是整数要么就是小数部分为0.5的小数,计算出中间结果之后判断能否被2整除,能就输出除以2得到的答案,不能就在这个答案后再加.5。总的面积要用64位int来保存。

    #include <cstdio>
    #include <cmath>
    #define vector point
    struct point
    {
        int x,y;
        point(int xx = 0,int yy = 0)
        {
            x = xx;
            y = yy;
        }
        point operator - (const point& s)
        {
            return point(x - s.x, y - s.y);
        }
    };
    int cross_product(vector v1,vector v2)
    {
        return v1.x * v2.y - v1.y * v2.x;
    }
    const int dir[10][2] = {{0,0},{-1,-1},{0,-1},{1,-1},{-1,0},{0,0},{1,0},{-1,1},{0,1},{1,1}};
    void move(point p1,point& p2,int x)
    {
        p2.x = p1.x + dir[x][0];
        p2.y = p1.y + dir[x][1];
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            __int64 s = 0;
            int x;
            point p1,p2;
            bool flag = false;
            p1 = point(0,0);
            while(scanf("%1d",&x) && x != 5)
            {
                move(p1,p2,x);
                s += cross_product(vector(p2),vector(p1));
                p1 = p2;
            }
            if(s < 0)
                s = -s;
            if(s % 2 == 0)
                printf("%I64d\n",s / 2);
            else
                printf("%I64d.5\n",s / 2);
        }
        return 0;
    }
  • 相关阅读:
    我的ORM之六-- 批量
    我的ORM之五-- 事务
    我的ORM之四--删除
    我的ORM之三 -- 更新
    我的ORM之二--添加
    我的ORM之一 -- 查询
    hmailserver
    jquery 插件原则
    C#中 ToString 和 override ToString 的区别
    linq操作符:元素操作符
  • 原文地址:https://www.cnblogs.com/ZShogg/p/3061440.html
Copyright © 2011-2022 走看看