poj3130 How I Mathematician Wonder What You Are!【半平面交】
2017-04-28 20:27
387 查看
题目链接:http://poj.org/problem?id=3130
题意:给你一个多边形,让你判断是否是星星,星星的定义是如果有两个点ab属于多边形里面,那么线段ab也属于多边形里面
解析:仔细想想,如果是星星的话,那么也就相当于这个多边形存在核,所以直接套半平面交的模板,记住输入时逆时针的
题意:给你一个多边形,让你判断是否是星星,星星的定义是如果有两个点ab属于多边形里面,那么线段ab也属于多边形里面
解析:仔细想想,如果是星星的话,那么也就相当于这个多边形存在核,所以直接套半平面交的模板,记住输入时逆时针的
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; const double eps = 0; const int maxn = 12+100; struct point { double x,y; point() {} point(double _x,double _y) { x = _x; y = _y; } }; point points[maxn],p[maxn],q[maxn]; int cCnt,curCnt; void init(int n) { for(int i=1;i<=n;i++) p[i] = points[i]; p[n+1] = p[1]; p[0] = p ; cCnt = n; } void getline(point s,point e,double &a,double &b,double &c) { a = e.y-s.y; b = s.x-e.x; c = e.x*s.y-s.x*e.y; } point cross(point p1,point p2,double a,double b,double c) { double u = fabs(a*p1.x+b*p1.y+c); double v = fabs(a*p2.x+b*p2.y+c); return point((p1.x*v+p2.x*u)/(u+v),(p1.y*v+p2.y*u)/(u+v)); } void cut(double a,double b,double c) { curCnt = 0; for(int i=1;i<=cCnt;i++) { if(a*p[i].x+b*p[i].y+c>=eps) q[++curCnt] = p[i]; else { if(a*p[i-1].x+b*p[i-1].y+c > eps) q[++curCnt] = cross(p[i],p[i-1],a,b,c); if(a*p[i+1].x+b*p[i+1].y+c > eps) q[++curCnt] = cross(p[i],p[i+1],a,b,c); } } for(int i=1;i<=curCnt;i++) p[i] = q[i]; p[curCnt+1] = q[1]; p[0] = p[curCnt]; cCnt = curCnt; } void slove(int n) { init(n); for(int i=1;i<=n;i++) { double a,b,c; getline(points[i],points[i+1],a,b,c); cut(a,b,c); } } void adjust(int n) { for(int i=1;i<=n;i++) q[i]=points[n-i+1]; for(int i=1;i<=n;i++) points[i]=q[i]; } int main(void) { int n; while(~scanf("%d",&n)&&n) { for(int i=1;i<=n;i++) scanf("%lf %lf",&points[i].x,&points[i].y); adjust(n); points[n+1] = points[1]; slove(n); if(cCnt<1) puts("0"); else puts("1"); } return 0; }
相关文章推荐
- POJ 3130 How I Mathematician Wonder What You Are! & 3335 Rotating Scoreboard (半平面交求多边形的核)
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
- POJ 3130 How I Mathematician Wonder What You Are! 半平面交
- poj 3130 How I Mathematician Wonder What You Are! 半平面交判断核存在问题
- poj 3130 How I Mathematician Wonder What You Are!(半平面交)
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交)
- [poj 3130]How I Mathematician Wonder What You Are![半平面交][模板题]
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
- POJ 3130 How I Mathematician Wonder What You Are! 半平面交求多边形内核是否存在
- poj 3130 How I Mathematician Wonder What You Are! 【半平面交】
- poj 3130 How I Mathematician Wonder What You Are! (半平面交)
- 【POJ 3130】How I Mathematician Wonder What You Are! ,Japan 2006(半平面交)
- POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
- POJ 3130: How I Mathematician Wonder What You Are! 半平面交
- POJ 3130-How I Mathematician Wonder What You Are!(计算几何-星形-半平面交逆时针模板)
- POJ 3130 || How I Mathematician Wonder What You Are!
- poj 3130 How I Mathematician Wonder What You Are!
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
- POJ 3335 Rotating Scoreboard & POJ 3130 How I Mathematician Wonder What You Are!