梦,才是最真的现实

导航

poj 1654 多边形面积计算

本以为是个大水题,贴个模版就了事了,没想到MLE,的确不能眼高手低

这个题目的memory卡的比较紧,先是MLE,后来是TLE,后来是WA。。。。各种可能的错误都有了,不过感觉除了MLE不是我的问题,

用get输入不知道为什么TLE,然后后GCC提交是WA,最后改为g++才是AC,是int64所致?

回到正题,贴个求多边形面积的连接http://zhidao.baidu.com/question/34974852.html

代码

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
typedef struct{__int64 x,y;}point;
typedef struct{point a,b;}line;
int n;
char string[1000005];
inline __int64 xmult(point p1,point p2,point p0)
{
	return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
void graham_scan();
int main()
{
	int t,i;
	point now,s,last;
	char c;
	__int64 are;
	s.x=s.y=0;
	for(scanf("%d",&t);t;t--)
	{
		scanf("%s",string);
		i=0;
		are=0;
		now.x=now.y=0;
		while(string[i]!='5')
		{
			last=now;
			c=string[i];
			if(c=='8') now.y++;
			else if(c=='2') now.y--;
			else if(c=='4') now.x--;
			else if(c=='6') now.x++;
			else if(c=='7') 
			{
				now.y++;
				now.x--;
			}
			else if(c=='9')
			{
				now.y++;
				now.x++;
			}
			else if(c=='1')
			{
				now.x--;
				now.y--;
			}
			else if(c=='3')
			{
				now.x++;
				now.y--;
			}
			are+=xmult(s,last,now);
			i++;
		}
		if(are<0) are=-are;
		printf("%I64d",are/2);
		if(are&1) printf(".5");
		printf("\n");
	}
	return 0;
}


posted on 2012-08-17 16:11  梦,才是最真的现实  阅读(291)  评论(0编辑  收藏  举报