Description
For example, this is a legal polygon to be computed and its area is 2.5:

Input
Output
Sample Input
4 5 825 6725 6244865
Sample Output
0 0 0.5 2
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct point
{
int x,y;
};
int det(point a,point b)
{//叉积求面积
return a.x*b.y-a.y*b.x;
}
//记录移动的坐标
int stand[10][2]={{0,0},{-1,-1},{0,-1},{1,-1},{-1,0},{0,0},{1,0},{-1,1},{0,1},{1,1}};
int main()
{
char a[1000001];
int i,t,n,str;
scanf("%d",&t);
point pointone,pointtwo;
while(t--)
{
long long s=0;
scanf("%s",&a);
str=strlen(a);
if(str==1||str==2)//小于3 肯定是0;
{
printf("0\n");
continue;
}
for(i=0;i<str-1;i++)
{
if(i==0)
{
pointone.x=stand[a[i]-'0'][0];
pointone.y=stand[a[i]-'0'][1];
}
else
{//开始求面积
pointtwo.x=pointone.x+stand[a[i]-'0'][0];
pointtwo.y=pointone.y+stand[a[i]-'0'][1];
s+=det(pointone,pointtwo);
pointone=pointtwo;
}
}
long long temp;
if(s<0)
{
s=-s;
}
temp=s/2;
if(temp*2==s)
{
printf("%lld\n",s/2);
}
else
{
printf("%lld.5\n",s/2);
}
}
return 0;
}
3766



被折叠的 条评论
为什么被折叠?



