POJ 2540 Hotter Colder
来源:互联网 发布:禁忌的边界线知乎 编辑:程序博客网 时间:2024/05/01 13:51
求中垂线的半平面交
注意这里出现一个'Same'之后就一直输出0.00了
#include<stdio.h>#include<math.h>using namespace std;const double eps=1e-8;struct Point { double x,y; Point () {}; Point (double xx,double yy) {x=xx;y=yy;}; double operator^(const Point b)const{ return x*b.y-y*b.x; } Point operator-(const Point b)const{ return Point(x-b.x,y-b.y); }};struct Line { Point s,e; Line(){}; Line(Point ss,Point ee){s=ss;e=ee;} Point operator &(const Line b)const { Point res=s; double t=((s-b.e)^(b.s-b.e))/((s-e)^(b.s-b.e)); res.x+=(e.x-s.x)*t; res.y+=(e.y-s.y)*t; return res; }};int n,cnt;Point s,e,p[105],q[105];Line t;char str[100];Line getline(Point s,Point e){ Point mid,t; mid.x=(s.x+e.x)/2; mid.y=(s.y+e.y)/2; t.x=e.y-mid.y; t.y=mid.x-e.x; t.x+=mid.x; t.y+=mid.y; return Line(mid,t);}void cut(Line t){ int curCnt=0; for(int i=1;i<=cnt;i++) { double s=(t.e-t.s)^(p[i]-t.s); if (str[0]=='H') s=-s; if (s<=eps) q[++curCnt]=p[i]; else { s=(t.e-t.s)^(p[i-1]-t.s); if (str[0]=='H') s=-s; if (s<-eps) q[++curCnt]=t&Line(p[i],p[i-1]); s=(t.e-t.s)^(p[i+1]-t.s); if (str[0]=='H') s=-s; if (s<-eps) q[++curCnt]=t&Line(p[i],p[i+1]); } } cnt=curCnt; q[0]=q[cnt]; q[cnt+1]=q[1]; for(int i=0;i<=cnt+1;i++) p[i]=q[i]; //printf("%d\n",cnt); double area=0; for(int i=1;i<=cnt;i++) { area+=p[i]^p[i+1]; //printf("%f %f\n",p[i].x,p[i].y); } area=fabs(area/2); if(area>eps) printf("%.2f\n",area); else printf("0.00\n");}int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endif // ONLINE_JUDGE s.x=0; s.y=0; p[1].x=0; p[1].y=0; p[2].x=10; p[2].y=0; p[3].x=10; p[3].y=10; p[4].x=0; p[4].y=10; p[5]=p[1]; p[0]=p[4]; cnt=4; while(scanf("%lf%lf%s",&e.x,&e.y,str)!=EOF){ Line t; t=getline(s,e); if (str[0]=='S') cnt=0; cut(t); //printf("%f %f %f %f\n",t.s.x,t.s.y,t.e.x,t.e.y); s=e; }}
0 0
- POJ 2540 Hotter Colder
- poj 2540 Hotter Colder
- POJ 2540 Hotter Colder
- POJ 2540 Hotter Colder 笔记
- poj 2540 Hotter Colder(线性规划可行区域)
- poj 2540 Hotter Colder 切割多边形
- POJ 2540 Hotter Colder(半平面交)
- poj 2540 Hotter Colder 半平面交
- zoj 1886 || poj 2540 || UVA 10084 Hotter Colder
- POJ 2540 Hotter Colder(半平面交求可行域)
- Poj 2540 Hotter Colder (半平面求交求可行域)
- poj 2540 && uva 10084 Hotter Colder(半平面交)
- POJ 2540 ZOJ 1886 Hotter Colder 半平面交
- poj 2540 Hotter Colder (半平面交+线性规划)
- POJ 2540 Hotter Colder 半平面交 求可行域面积
- uva 10084 Hotter Colder
- POJ2540/ZOJ1886 Hotter Colder
- POJ2540-Hotter Colder(半平面交)
- uva 1368 - DNA Consensus String(字符串处理)
- 2014年心得体会
- Windows下安装OpenSSL及其使用
- nginx localhost 配置,开启目录浏览
- android 限制广播消息的接收者
- POJ 2540 Hotter Colder
- shell编程位置变量
- Motivated Word(3)
- C++BM算法
- TCC研究(2) 把C语言当作脚本,解释执行,并嵌入各类程序
- poj1019 Number Sequence
- 【BZOJ3209】花神的数论题 数位DP(我姿势不标准,但是可能更好写)
- The Third (构造函数,final )
- 远程触发SYSRQ获取最新的dmesg信息-一个几乎没有什么用的方案