题意:逆时针给出N个点,求这个多边形是否有核。

思路:半平面交求多边形是否有核。模板题。

定义:

多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 )。核内的点与多边形所有顶点的连线均在多边形内部。

半平面交:对于平面,任何直线都能将平面划分成两部分,即两个半平面。半平面交既是多个半平面的交集。定义如其名。

半平面交求多边形的核。

设多边形点集为 *p,核的点集为*cp。

开始时将p的所有点放到cp内,然后枚举多边形的所有边去切割cp,cp中在边内侧的点保留,外侧的点删除,注意添加交点。

在边的内侧或外侧可以用叉乘来判断,还有注意多边形点集的顺序是逆时针还是顺时针。

将3130的代码中的1改成 YES,0 改成 NO  ,大于-EPS 改成 小于 EPS  就是 3335的代码。。。。。。无耻的暗爽中

POJ 3130

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string> #define LL long long
#define EPS (1e-9)
#define Right 1;
#define Left -1; using namespace std; struct P
{
double x,y;
} p[55],tp[2510],cp[2510]; double X_Mul(P a1,P a2,P b1,P b2)
{
P v1 = {a2.x-a1.x,a2.y-a1.y},v2 = {b2.x-b1.x,b2.y-b1.y};
return v1.x*v2.y - v1.y*v2.x;
} P Cal_Cross_Position(P a1,P a2,P b1,P b2)
{
double t = fabs(X_Mul(a1,a2,a1,b1))/fabs(X_Mul(a1,a2,b2,b1));
P p = {b1.x + (b2.x-b1.x)*t,b1.y + (b2.y-b1.y)*t};
return p;
} int Cut_Polygon(P a1,P a2,P *tp,int n,P *cp)
{
double xm1,xm2;
int i ,top = 0;
for(i = 0;i < n; ++i)
{
xm1 = X_Mul(a1,a2,a1,tp[i]),xm2 = X_Mul(a1,a2,a1,tp[i+1]);
if(xm1 > -EPS && xm2 > -EPS)
{
cp[top++] = tp[i];
}
else if(xm1 > -EPS || xm2 > -EPS)
{
if(xm1 > -EPS)
{
cp[top++] = tp[i];
}
cp[top++] = Cal_Cross_Position(a1,a2,tp[i],tp[i+1]);
}
}
cp[top] = cp[0];
return top;
} void Is_Star(P *tp,P *cp,P *p,int n)
{
int i,j,top; for(i = 0;i <= n; ++i)
{
tp[i] = p[i];
} for(top = n,i = 0;i < n; ++i)
{
top = Cut_Polygon(p[i],p[i+1],tp,top,cp);
//cout<<"top = "<<top<<endl;
if(top == 0)
{
cout<<"0"<<endl;
return ;
} for(j = 0;j <= top; ++j)
{
tp[j] = cp[j];
} }
cout<<"1"<<endl;
} int main()
{
int i,n;
while(scanf("%d",&n) && n)
{
for(i = 0; i < n; ++i)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
} p[n] = p[0]; Is_Star(tp,cp,p,n);
}
return 0;
}

POJ 3335

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string> #define LL long long
#define EPS (1e-9)
#define Right 1;
#define Left -1; using namespace std; struct P
{
double x,y;
} p[55],tp[2510],cp[2510]; double X_Mul(P a1,P a2,P b1,P b2)
{
P v1 = {a2.x-a1.x,a2.y-a1.y},v2 = {b2.x-b1.x,b2.y-b1.y};
return v1.x*v2.y - v1.y*v2.x;
} P Cal_Cross_Position(P a1,P a2,P b1,P b2)
{
double t = fabs(X_Mul(a1,a2,a1,b1))/fabs(X_Mul(a1,a2,b2,b1));
P p = {b1.x + (b2.x-b1.x)*t,b1.y + (b2.y-b1.y)*t};
return p;
} int Cut_Polygon(P a1,P a2,P *tp,int n,P *cp)
{
double xm1,xm2;
int i ,top = 0;
for(i = 0;i < n; ++i)
{
xm1 = X_Mul(a1,a2,a1,tp[i]),xm2 = X_Mul(a1,a2,a1,tp[i+1]);
if(xm1 < EPS && xm2 < EPS)
{
cp[top++] = tp[i];
}
else if(xm1 < EPS || xm2 < EPS)
{
if(xm1 < EPS)
{
cp[top++] = tp[i];
}
cp[top++] = Cal_Cross_Position(a1,a2,tp[i],tp[i+1]);
}
}
cp[top] = cp[0];
return top;
} void Is_Star(P *tp,P *cp,P *p,int n)
{
int i,j,top; for(i = 0;i <= n; ++i)
{
tp[i] = p[i];
} for(top = n,i = 0;i < n; ++i)
{
top = Cut_Polygon(p[i],p[i+1],tp,top,cp);
//cout<<"top = "<<top<<endl;
if(top == 0)
{
cout<<"NO"<<endl;
return ;
} for(j = 0;j <= top; ++j)
{
tp[j] = cp[j];
} }
cout<<"YES"<<endl;
} int main()
{
int i,n;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i = 0; i < n; ++i)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
} p[n] = p[0]; Is_Star(tp,cp,p,n);
}
return 0;
}

POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交的更多相关文章

  1. poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版

    /* poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */ #include <stdio.h> #include ...

  2. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...

  3. poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 25 ...

  4. POJ 3130 How I Mathematician Wonder What You Are! (半平面交)

    题目链接:POJ 3130 Problem Description After counting so many stars in the sky in his childhood, Isaac, n ...

  5. POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)

    题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...

  6. poj 3130 How I Mathematician Wonder What You Are!

    http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...

  7. POJ 3130 How I Mathematician Wonder What You Are! (半平面相交)

    Description After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a ...

  8. POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)

    题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...

  9. poj 3130 How I Mathematician Wonder What You Are! 【半平面交】

    求多边形的核,直接把所有边求半平面交判断有无即可 #include<iostream> #include<cstdio> #include<algorithm> # ...

随机推荐

  1. POJ1035——Spell checker(字符串处理)

    Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...

  2. 启用了不安全的HTTP方法

    安全风险:       可能会在Web 服务器上上载.修改或删除Web 页面.脚本和文件. 可能原因:       Web 服务器或应用程序服务器是以不安全的方式配置的. 修订建议:       如果 ...

  3. 智传播客hadoop视频学习笔记(共2天)

    第一天:1.答疑解惑•  就业前景•  学习hadoop要有什么基础•  hadoop会像塞班一样,热一阵子吗•  hadoop学习起来容易还是困难•  课堂上的学习方法(所有实验必须按照要求做,重原 ...

  4. MySQL 普通索引、唯一索引和主索引

    1.普通索引 普通索引(由关键字KEY或INDEX定义的索引)的唯一任务是加快对数据的访问速度.因此,应该只为那些最经常出现在查询条件(WHEREcolumn=)或排序条件(ORDERBYcolumn ...

  5. 使用net start mysql的时候出现服务名无效的原因及解决办法

    原因:mysql服务没有安装 解决办法:使用管理员权限,执行mysqld -install命令 然后以管理员身份net start mysql开启mysql服务 卸载mysql服务的方法 1.管理员权 ...

  6. ☀Chrome模拟移动端浏览器

  7. Ejabberd源码解析前奏--集群

    一.如何工作 一个XMPP域是由一个或多个ejabberd节点伺服的. 这些节点可能运行在通过网络连接的不同机器上. 它们都必须有能力连接到所有其它节点的4369端口, 并且必须有相同的 magic ...

  8. 也用 Log4Net 之将日志记录到数据库的后台实现 (二)

    也用 Log4Net 之将日志记录到数据库的后台实现 (二)  大家下午好,昨天讲了配置,今天我们讲讲后台实现,在完成了后台实现后,我们才能真正意义上的解决把自定义属性字段值录入到数据库中. 在开写之 ...

  9. 枚举类型的单例模式(java)

    Inspired by Effective Java. Singleton模式是在编程实践中应用最广泛的几种设计模式之一.以前知道的,实现单例的方法有两种(下面的A.B).刚刚在读<Effect ...

  10. 【译】 AWK教程指南 11递归程序

    awk 中除了函数的参数列表(Argument List)上的参数(Arguments)外,所有变量不管于何处出现,全被视为全局变量.其生命持续至程序结束——该变量不论在function外或 func ...