POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交
题意:逆时针给出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 初涉半平面交的更多相关文章
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
/* poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 */ #include <stdio.h> #include ...
- poj 3335 Rotating Scoreboard - 半平面交
/* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...
- poj 3335 Rotating Scoreboard(半平面交)
Rotating Scoreboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6420 Accepted: 25 ...
- 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 ...
- POJ 3335 Rotating Scoreboard(半平面交 多边形是否有核 模板)
题目链接:http://poj.org/problem? id=3335 Description This year, ACM/ICPC World finals will be held in a ...
- poj 3130 How I Mathematician Wonder What You Are!
http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...
- 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 ...
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
题目链接 题意 : 给你一个多边形,问你该多边形中是否存在一个点使得该点与该多边形任意一点的连线都在多边形之内. 思路 : 与3335一样,不过要注意方向变化一下. #include <stdi ...
- poj 3130 How I Mathematician Wonder What You Are! 【半平面交】
求多边形的核,直接把所有边求半平面交判断有无即可 #include<iostream> #include<cstdio> #include<algorithm> # ...
随机推荐
- Apache Tomcat下载、安装、配置图文教程
本文已迁移到我的个人网站 http://www.wshunli.com 文章地址: http://www.wshunli.com/2016/03/19/Tomcat安装配置/ (整理截图.安装过程更加 ...
- UVA 10041 Vito's Family (中位数)
Problem C: Vito's family Background The world-known gangster Vito Deadstone is moving to New York ...
- 【剑指offer】数字在排序数组中出现的次数
2013-09-02 16:28:35 找出数字在排序数组中出现的次数. 注意几点: 一开始试图用size_t类型表示数组的下标begin.end,到那时这样做在end = 0时,end - 1是si ...
- Android访问C#的WebService要注意的问题
@Overrideprotected String doInBackground(Object... params) { // 根据命名空间和方法得到SoapObject对象 SoapObject s ...
- js jquery版本的 金额千分位转换函数(非正则,效率极高)
没想到js里面没有 金额千分位格式化的处理函数(例:1,234.01 这样的格式),网上搜了一圈,都是使用正则的方式处理的.正则的效率不敢恭维啊,又耗费资源速度又慢(虽然处理起来会直观一些). 因此专 ...
- C++学习笔记:Vector容器
vector v:初始化一个0大小的向量 vector v(10):初始化一个10个大小的向量 push_back:增加一个元素 pop:删除一个元素,不返回 front:返回第一个元素 back:返 ...
- Ejabberd源码解析前奏--集群
一.如何工作 一个XMPP域是由一个或多个ejabberd节点伺服的. 这些节点可能运行在通过网络连接的不同机器上. 它们都必须有能力连接到所有其它节点的4369端口, 并且必须有相同的 magic ...
- AM335x(TQ335x)学习笔记——挂载Ramdisk
上篇文章中我们已经能够通过u-boot启动内核了,但是没有能够启动成功,从内核的log中可以看出,内核启动失败的原因是没有挂载到root文件系统,本文将使用busybox制作根文件系统并打包成ramd ...
- 转载crontab例行工作调度
转自:http://blog.sina.com.cn/s/blog_95ee143401017y70.html crontab [-e [UserName]|-l [UserName]|-r [Use ...
- poj2686-Traveling by Stagecoach(状压dp)
题意: n张马票,m个城市,马票上有马数(决定速度),一张只能用一次,给出地图,求从城市a到b的最短时间. 分析:n值很小状态压缩 #include <map> #include < ...