poj 1654 Area 多边形面积
生活随笔
收集整理的這篇文章主要介紹了
poj 1654 Area 多边形面积
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*
poj 1654 Area 多邊形面積題目意思很簡單,但是1000000的point開不了
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
const int N=1000000+10;
const double eps=1e-8;
struct point
{double x,y;point(){}point(double a,double b):x(a),y(b){}
};
int len,index;
char t_s[N];
//基礎函數/
double mo_distance(point p1,point p2)
{return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double mo_xmult(point p2,point p0,point p1)//p1在p2左返回負,在右邊返回正
{return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}bool mo_ee(double x,double y)
{double ret=x-y;if(ret<0) ret=-ret;if(ret<eps) return 1;return 0;
}
bool mo_gg(double x,double y) { return x > y + eps;} // x > y
bool mo_ll(double x,double y) { return x < y - eps;} // x < y
bool mo_ge(double x,double y) { return x > y - eps;} // x >= y
bool mo_le(double x,double y) { return x < y + eps;} // x <= y //求多邊形面積
double area_polygon(point shang,point zhe)
{point yuan;yuan.x=yuan.y=0;return mo_xmult(zhe,yuan,shang)/2;
}///
int getpoint(point shang,point &zhe)
{if(t_s[index]=='5')return 0;;char doo=t_s[index];int n=1;while(t_s[index+1]==t_s[index]){++n;++index;}++index;if(doo=='1'){zhe.x=shang.x-n;zhe.y=shang.y-n;}else if(doo=='2'){zhe.x=shang.x;zhe.y=shang.y-n;}else if(doo=='3'){zhe.x=shang.x+n;zhe.y=shang.y-n;}else if(doo=='4'){zhe.x=shang.x-n;zhe.y=shang.y;}else if(doo=='9'){zhe.x=shang.x+n;zhe.y=shang.y+n;}else if(doo=='6'){zhe.x=shang.x+n;zhe.y=shang.y;}else if(doo=='7'){zhe.x=shang.x-n;zhe.y=shang.y+n;}else if(doo=='8'){zhe.x=shang.x;zhe.y=shang.y+n;}return 1;
}
int main()
{int t;scanf("%d",&t);getchar();while(t--){gets(t_s);len=strlen(t_s);index=0;point shang(0,0),zhe;double area=0;while(getpoint(shang,zhe)){area+=area_polygon(shang,zhe);shang=zhe;}if(area<0)area=-area;__int64 ret=(__int64)area,i;for(i=ret;i<=ret+2;++i){if(mo_ee((double)i,area)){printf("%I64d\n",i);break;}else if(mo_ee(0.5+i,area)){printf("%I64d.5\n",i);}}}return 0;
}
轉載于:https://www.cnblogs.com/dyllove98/p/3233905.html
總結
以上是生活随笔為你收集整理的poj 1654 Area 多边形面积的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: javaSE-多线程1
- 下一篇: java jdk API中英文下载