POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
2014-09-06 15:48
363 查看
题目链接
题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内。
思路 : 与3335一样,不过要注意方向变化一下。
View Code
题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内。
思路 : 与3335一样,不过要注意方向变化一下。
#include <stdio.h> #include <string.h> #include <iostream> #include <math.h> using namespace std ; struct node { double x; double y ; } p[110],temp[110],newp[110];//p是最开始的多边形的每个点,temp是中间过程中临时存的多边形的每个点,newp是切割后的多边形的每个点 int n,newn ;//原来的点数,切割后的点数 double a,b,c ;//直线方程的三个系数 void getline(node x,node y)//求x与y两点确定的直线方程ax+by+c=0 { a = y.y-x.y ; b = x.x-y.x ; c = y.x*x.y - y.y*x.x ; } node intersect(node x,node y)//求x与y点确定的直线与ax+by+c=0这条直线的交点 { double u = fabs(a*x.x+b*x.y+c) ; double v = fabs(a*y.x+b*y.y+c) ; node t ; t.x = (x.x*v+y.x*u)/(u+v) ;//y.y-x.y=u+v;y.y-t.y=v;y.y-x.y=u; t.y = (x.y*v+y.y*u)/(u+v) ; return t ; } void cut() { int cutn = 0 ; for(int i = 1 ; i <= newn ; i++) { if(a*newp[i].x+b*newp[i].y+c >= 0)//所有的点都大于0,说明所有的点都在这条直线的另一边,所以不用切 temp[ ++cutn] = newp[i] ; else { if(a*newp[i-1].x+b*newp[i-1].y+c > 0) temp[++cutn ] = intersect(newp[i-1],newp[i]) ;//把新交点加入 if(a*newp[i+1].x+b*newp[i+1].y+c > 0) temp[ ++cutn] = intersect(newp[i+1],newp[i]) ; } } for(int i = 1 ; i <= cutn ; i++) newp[i] = temp[i] ; newp[cutn+1] = temp[1] ;//能够找出所有点的前驱和后继 newp[0] = temp[cutn] ; newn = cutn ; } void solve() { for(int i = 1 ; i <= n ; i++) { newp[i] = p[i] ; } p[n+1] = p[1] ; newp[n+1] = newp[1] ; newp[0] = newp ; newn = n ; for(int i = 1 ; i <= n ; i++) { getline(p[i],p[i+1]) ;//从头开始顺序遍历两个相邻点。 cut() ; } } void guizhenghua() { for(int i = 1 ; i < (n+1)/2 ; i++)//规整化方向,顺时针变逆时针,逆时针变顺时针。 swap(p[i],p[n-i]) ; } int main() { while(scanf("%d",&n)!=EOF && n) { for(int i = 1 ; i <= n ; i++) scanf("%lf %lf",&p[i].x,&p[i].y) ; guizhenghua() ; p[n+1] = p[1] ; solve() ; if(newn == 0) puts("0") ; else puts("1") ; } return 0; }
View Code
相关文章推荐
- 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! & 3335 Rotating Scoreboard (半平面交求多边形的核)
- POJ 3130 How I Mathematician Wonder What You Are! 半平面交
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
- POJ 3130 & ZOJ 2820 How I Mathematician Wonder What You Are!(半平面相交 多边形是否有核)
- How I Mathematician Wonder What You Are! - POJ 3130(求多边形的核)
- 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! - 求多边形有没有核 - 模版
- 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! 【半平面交】
- poj3130 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(半平面交)