POJ 1654 || Area(求多边形面积

7 8 9

4 5 6

1 2 3

如上键位,从原点开始,按数字几就是往哪个方向走,5停止

求从原点开始,走过这些的路径围成的多边形的面积,用叉积来算就好了,以原点为起点,很easy

不过爆int了没弄清楚范围,wa了几发!!!!!

还有就是哪个输出,一定要弄成这样,我试了别的都wa。。。

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;
string str;
int maps[10][2]={0,0,-1,-1,0,-1,1,-1,-1,0,0,0,1,0,-1,1,0,1,1,1};
int main()
{
    int cas;
    scanf("%d",&cas);
    while(cas--)
    {
        cin>>str;
        int len = str.length();
        if(  len<=2 )
            puts("0");
        else{

            long long x,y,xx,yy;
            x = y = 0;
            long long ans = 0.0;
            for( int i = 0;i < len-1; ++i){
                xx = x+maps[str[i]-'0'][0];
                yy = y+maps[str[i]-'0'][1];
                ans += x*yy - y*xx;
                x = xx;
                y = yy;
            }
             if(ans<0) ans=(-1)*ans;
             if(ans%2==0)
               printf("%lld\n",ans/2);
             else printf("%lld.5\n",ans/2);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值