poj 3335 Rotating Scoreboard(半平面交)
2013-09-02 19:09
429 查看
第一道半平面交的题,给一个多边形,问是否存在核,/article/8132727.html这个博客讲得很好。
#include<iostream> #include<cstdio> #include<string.h> #include<algorithm> #include<math.h> #include<queue> #include<stack> #include<map> #include<vector> #define mm(a,b) memset(a,b,sizeof(a)) #define maxn 105 using namespace std; const int inf=0x7ffffff; const double PI=acos(-1.0); const double eps=1e-8; const double e=2.7182818284590452354; struct point { double x,y; point() {} point(double x,double y): x(x),y(y) {} }p[maxn],q[maxn],pnt[maxn]; int cnt,curcnt; void initial(int n) { for(int i=1;i<=n;i++) p[i]=pnt[i]; p[n+1]=p[1]; p[0]=p ; cnt=n; } //两点确定直线 void getline(point x,point y,double &a,double &b,double &c) { a=y.y-x.y; b=x.x-y.x; c=y.x*x.y-x.x*y.y; } //求交点 point intersect(point x,point y,double a,double b,double c) { double u=fabs(a*x.x+b*x.y+c); double v=fabs(a*y.x+b*y.y+c); return point((v*x.x+u*y.x)/(u+v),(v*x.y+u*y.y)/(u+v)); } //直线切割 void cut(double a,double b,double c) { curcnt=0; for(int i=1;i<=cnt;i++) { if(a*p[i].x+b*p[i].y+c>=0)//当前点在直线右侧 q[++curcnt]=p[i]; else { if(a*p[i-1].x+b*p[i-1].y+c>0)//前一个点在直线右侧 q[++curcnt]=intersect(p[i],p[i-1],a,b,c); if(a*p[i+1].x+b*p[i+1].y+c>0)//同理 q[++curcnt]=intersect(p[i],p[i+1],a,b,c); } } for(int i=1;i<=curcnt;i++) p[i]=q[i]; p[curcnt+1]=p[1]; p[0]=p[curcnt]; cnt=curcnt; } int main() { int n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf",&pnt[i].x,&pnt[i].y); pnt[n+1]=pnt[1]; initial(n); //顺时针方向 for(int i=1;i<=n;i++) { double a,b,c; getline(pnt[i],pnt[i+1],a,b,c); cut(a,b,c); } if(cnt<1) puts("NO"); else puts("YES"); } return 0; }
相关文章推荐
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
- poj 3335 Rotating Scoreboard(半平面交)
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
- Poj 3335 Rotating Scoreboard [半平面交判断内核]
- poj 3335 Rotating Scoreboard - 半平面交
- poj 3335 Rotating Scoreboard - 半平面交
- poj 3335 Rotating Scoreboard(半平面交,求解多边形内核)
- POJ 3335 Rotating Scoreboard 半平面交
- POJ 3130 How I Mathematician Wonder What You Are! & 3335 Rotating Scoreboard (半平面交求多边形的核)
- POJ 3335 Rotating Scoreboard 半平面交
- POJ 3335: Rotating Scoreboard 半平面交
- [poj 3335]Rotating Scoreboard[半平面交模板题]
- POJ 3335 Rotating Scoreboard【半平面交_多边形内核】
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
- POJ_3335_Rotating Scoreboard(半平面交的核)
- poj 3335 Rotating Scoreboard(半平面交)
- Rotating Scoreboard - POJ 3335 半平面交
- poj 3335 Rotating Scoreboard (半平面交)
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
- poj 3335 Rotating Scoreboard 半平面交