现在的位置: 首页 > 综合 > 正文

poj1654—计算几何

2013年09月02日 ⁄ 综合 ⁄ 共 915字 ⁄ 字号 评论关闭
//无比之水,按照题目要求做就行,求面积时,把面积之和后,在除2,避免精度缺失。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#define dist(a,b) sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))
#define cross(a,b,c) (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)
#define dot(a,b,c) (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y)
#define delt(a) fabs(a)<eps?0:a>0?1:-1
#define pi acos(-1.0)
#define eps 1e-8
#define inf 1e20
#define N 1000005
#define M 1005
using namespace std;
typedef __int64 i64;
struct TPoint
{
	int x,y;
}a,b,c;
int n;
int dir[10][2]={{0,0},{-1,-1},{0,-1},{1,-1},{-1,0},{0,0},{1,0},{-1,1},{0,1},{1,1}};
char str[N];
i64 sumf;
int main()
{
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",str);
        int len = strlen(str);
        int i,j,k;
        a.x=0,a.y=0;
        c.x=a.x+dir[str[0]-'0'][0];
        c.y=a.y+dir[str[0]-'0'][1];
        for(i=1,sumf=0;i<len;i++)
        {
			b=c;
            c.x=b.x+dir[str[i]-'0'][0];
            c.y=b.y+dir[str[i]-'0'][1];
            sumf+=cross(a,b,c);
        }
        if(sumf<0) sumf=-sumf;
        printf("%I64d",sumf/2);
        if(sumf&1) printf(".5");
		puts("");
    }
    return 0;
}

抱歉!评论已关闭.