閱讀506 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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;
}


最後更新:2017-04-03 22:15:30

  上一篇:go 穀歌Chrome OS能帶來PC產業的革命嗎?
  下一篇:go fork 和 sigchld 坑