POJ 1654 多边形面积

简介:

求多边形面积,用到相邻两点叉积求多边形面积。

#include <iostream>
#include<cstdio>
using namespace std;
char s[1000005];
int stepx[10]= {0,-1,0,1,-1,0,1,-1,0,1},
               stepy[10]= {0,-1,-1,-1,0,0,0,1,1,1};

int main()
{
    int x,y,x1,y1,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",s);
        long long ans=0;
        x=y=0;
        for(int i=0; s[i]!='5'; i++)
        {
            x1=x+stepx[s[i]-'0'];
            y1=y+stepy[s[i]-'0'];
            ans+=x1*y-y1*x;
            x=x1,y=y1;
        }
        ans=ans<0?-ans:ans;
        if(ans&1)
            printf("%lld.5\n",ans/2);
        else
            printf("%lld\n",ans/2);
    }
    return 0;
}


目录
相关文章
|
9月前
|
算法 数据建模
Poj 3169(差分约束系统)
Poj 3169(差分约束系统)
39 0
|
人工智能 机器学习/深度学习
|
人工智能 算法 BI
poj 2192 Zipper
题目链接:http://poj.org/problem?id=2192 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18658   Accepted: 6651 Description Given ...
987 0
poj 1455
Description n participants of > sit around the table. Each minute one pair of neighbors can change their places.
626 0
|
测试技术
poj-1218 THE DRUNK JAILER 喝醉的狱卒
自己去看看原题; 题目大意: 就是一个狱卒喝醉了,他第一趟吧所有的监狱都带开,第二趟把能把二整除的监狱关闭,第三趟操作能把三整除的监狱; 求最后能逃跑的罪犯数 输入第一个数是代表 测试数据组数 每个数据代表狱卒来回的次数 当作开关问题即可 #include using names...
1024 0
poj-2551-ones
Description Given any integer 0
784 0