UVA 10256 The Great Divide (凸包,多边形的位置关系)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34148
【思路】
凸包
求出红蓝点的凸包,剩下的问题就是判断两个凸包是否相离。
需要确定两点:
1) 凸包上线段是否相交->相交
2) 凸包上的点是否包含在另一个凸包里->内含。
【代码】
#include<cmath>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std; const double eps = 1e-;
int dcmp(double x) {
if(fabs(x)<eps) return ; else return x<? -:;
} struct Pt {
double x,y;
Pt(double x=,double y=):x(x),y(y) {};
};
typedef Pt vec;
vec operator - (Pt A,Pt B) { return vec(A.x-B.x,A.y-B.y); }
bool operator == (Pt A,Pt B) {
return dcmp(A.x-B.x)== && dcmp(A.y-B.y)==;
}
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
double Dot(vec A,vec B) { return A.x*B.x+A.y*B.y;}
double cross(Pt A,Pt B) { return A.x*B.y-A.y*B.x; } bool SegIntersection(Pt a1,Pt a2,Pt b1,Pt b2) {
double c1 = cross(a2-a1,b1-a1), c2 = cross(a2-a1,b2-a1),
c3 = cross(b2-b1,a1-b1), c4=cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)< && dcmp(c3)*dcmp(c4)<;
}
bool OnSeg(Pt p,Pt a1,Pt a2) {
return dcmp(cross(p-a1,p-a2))== && dcmp(Dot(p-a1,p-a2))<;
} int n;
vector<Pt> ConvexHull(vector<Pt> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size();
int m=;
vector<Pt> ch(n+);
for(int i=;i<n;i++) {
while(m> && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--) {
while(m>k && cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
ch.resize(m);
return ch;
} int IsPointinPolygon(Pt p,vector<Pt>& poly) {
int wn=;
int n=poly.size();
for(int i=;i<n;i++) {
Pt& p1=poly[i];
Pt& p2=poly[(i+)%n];
if(p1==p || p2==p || OnSeg(p,p1,p2)) return -;
int k=dcmp(cross(p2-p1,p-p1));
int d1=dcmp(p1.y-p.y);
int d2=dcmp(p2.y-p.y);
if(k> && d1<= && d2>) wn++;
if(k< && d2<= && d1>) wn--;
}
if(wn!=) return ;
return ;
}
bool ConvexPolygonDisjoint(vector<Pt> ch1,vector<Pt> ch2) {
int c1=ch1.size() , c2=ch2.size();
for(int i=;i<c1;i++)
if(IsPointinPolygon(ch1[i],ch2)!=) return false;
for(int i=;i<c2;i++)
if(IsPointinPolygon(ch2[i],ch1)!=) return false;
for(int i=;i<c1;i++)
for(int j=;j<c2;j++)
if(SegIntersection(ch1[i],ch1[(i+)%c1],ch2[j],ch2[(j+)%c2])) return false;
return true;
} int main() {
int n,m;
while(scanf("%d%d",&n,&m)== && n && m) {
vector<Pt> P1,P2;
double x,y;
for(int i=;i<n;i++) {
scanf("%lf%lf",&x,&y);
P1.push_back(Pt(x,y));
}
for(int i=;i<m;i++) {
scanf("%lf%lf",&x,&y);
P2.push_back(Pt(x,y));
}
if(ConvexPolygonDisjoint(ConvexHull(P1),ConvexHull(P2)))
puts("Yes"); else puts("No");
}
return ;
}
UVA 10256 The Great Divide (凸包,多边形的位置关系)的更多相关文章
- UVA 10256 The Great Divide(凸包划分)
The Great Divide Input: standard input Output: standard output Time Limit: 8 seconds Memory Limit: 3 ...
- Cupid's Arrow---hdu1756(判断点与多边形的位置关系 模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1756 题意:中文题,套模板即可: /* 射线法:判断一个点是在多边形内部,边上还是在外部,时间复杂度为 ...
- LightOj1190 - Sleepwalking(判断点与多边形的位置关系--射线法模板)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1190 题意:给你一个多边形含有n个点:然后又m个查询,每次判断点(x, y)是否在多边 ...
- ZOJ1081 Points Within 点和多边形的位置关系
ZOJ1081 给一个点和一个多边形 判断点在多边形内(边上)还是在多边形外 在多边形外的点引一条射线必然穿过多边形的两条边 而在多边形内的点则不一定. 当然凹多边形有特殊情况 但是总能找到对应位置关 ...
- UVa 10256 - The Great Divide 判断凸包相交
模板敲错了于是WA了好几遍…… 判断由红点和蓝点分别组成的两个凸包是否相离,是输出Yes,否输出No. 训练指南上的分析: 1.任取红凸包上的一条线段和蓝凸包上的一条线段,判断二者是否相交.如果相交( ...
- UVa 10256 (判断两个凸包相离) The Great Divide
题意: 给出n个红点,m个蓝点.问是否存在一条直线使得红点和蓝点分别分布在直线的两侧,这些点不能再直线上. 分析: 求出两种点的凸包,如果两个凸包相离的话,则存在这样一条直线. 判断凸包相离需要判断这 ...
- UVa 10256 The Great Divide,推断两个凸包是否相离
先从给出的两个点集中分别计算出两个凸包, 然后推断两个凸包是否相离. #include<cstdio> #include<vector> #include<cmath&g ...
- UVA 10256 The Great Divide(点在多边形内)
The Great Divid [题目链接]The Great Divid [题目类型]点在多边形内 &题解: 蓝书274, 感觉我的代码和刘汝佳的没啥区别,可是我的就是wa,所以贴一发刘汝佳 ...
- uva 10256 The Great Divide
题意:给定两个点集,一个红点集,另一个蓝点集,询问,能否找到一条直线能,使得任取一个红点和蓝点都在直线异侧. 思路:划分成两个凸包,一个红包,一个蓝包.两个凸包不相交不重合. 1.任取一个凸包中的点不 ...
随机推荐
- Codevs 1074 食物链 2001年NOI全国竞赛
1074 食物链 2001年NOI全国竞赛 时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 动物王国中有三类动物 A,B ...
- 初学c++
今天在计蒜客中学习了c++的语句编写方法.因为之前编程时候用的都是c,所以第一次看到c++的部分代码还是有点迷茫忙的. 初次接触c++,我学习到了c++中变量的定义以及输入输出. 代码如下: #inc ...
- (poj)3414 Pots (输出路径的广搜)
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- IDE开发<LER-Studio>(2)::登录模块
软件中写登录模块是为了防止软件的恶意传播,内测阶段可以忽略登录. 以下为登录模块主要源代码: void CLoginDlg::OnBnClickedBtnLogin() { // TODO: Add ...
- Qt 获得终端执行结果
代码 话不多直接上本人代码 void MainWindow::on_pushButton_3_clicked() { myprocess = new QProcess(this); myprocess ...
- atc游戏bot
游戏玩起来太虐心了,就写了个bot来玩, 代码在此: git clone https://github.com/chenfengyuan/atc-bot-new.gitgit clone https: ...
- Jquery 动态生成表单 并将表单数据 批量通过Ajax插入到数据库
利用Jquery 动态生成 Table 表单 之后利用each 方法来遍历所有文本框获取文本的value值 并通过Ajax 将数据 提交到Web服务里把数据插入数据库 Html页面 <!DOC ...
- ubuntu server修改时区
公司用的是ubuntu server 服务器在美国亚马逊VPS 现在要修改时区 执行:tzselect 或直接修改 /etc/timezone 文件,我是改成(America/Los_Angeles) ...
- Extjs发票管理系统
技术特点:Extjs框架,三层架构,Ajax,json 1.仿office2007菜单.介面美观大方,可动态更改皮肤保存至cookie. 2,json数据源与实体类的相互转换. 3.可下载桌面版登录方 ...
- PHP下拉框选择的实现方法
实现 第一种PHP下拉框实现方法: < ?php //提交下拉框; //直接饱触发onchange事件的结果 $id=$_GET['myselect']; // myselect 为locati ...