题目链接: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 (凸包,多边形的位置关系)的更多相关文章

  1. UVA 10256 The Great Divide(凸包划分)

    The Great Divide Input: standard input Output: standard output Time Limit: 8 seconds Memory Limit: 3 ...

  2. Cupid's Arrow---hdu1756(判断点与多边形的位置关系 模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1756 题意:中文题,套模板即可: /* 射线法:判断一个点是在多边形内部,边上还是在外部,时间复杂度为 ...

  3. LightOj1190 - Sleepwalking(判断点与多边形的位置关系--射线法模板)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1190 题意:给你一个多边形含有n个点:然后又m个查询,每次判断点(x, y)是否在多边 ...

  4. ZOJ1081 Points Within 点和多边形的位置关系

    ZOJ1081 给一个点和一个多边形 判断点在多边形内(边上)还是在多边形外 在多边形外的点引一条射线必然穿过多边形的两条边 而在多边形内的点则不一定. 当然凹多边形有特殊情况 但是总能找到对应位置关 ...

  5. UVa 10256 - The Great Divide 判断凸包相交

    模板敲错了于是WA了好几遍…… 判断由红点和蓝点分别组成的两个凸包是否相离,是输出Yes,否输出No. 训练指南上的分析: 1.任取红凸包上的一条线段和蓝凸包上的一条线段,判断二者是否相交.如果相交( ...

  6. UVa 10256 (判断两个凸包相离) The Great Divide

    题意: 给出n个红点,m个蓝点.问是否存在一条直线使得红点和蓝点分别分布在直线的两侧,这些点不能再直线上. 分析: 求出两种点的凸包,如果两个凸包相离的话,则存在这样一条直线. 判断凸包相离需要判断这 ...

  7. UVa 10256 The Great Divide,推断两个凸包是否相离

    先从给出的两个点集中分别计算出两个凸包, 然后推断两个凸包是否相离. #include<cstdio> #include<vector> #include<cmath&g ...

  8. UVA 10256 The Great Divide(点在多边形内)

    The Great Divid [题目链接]The Great Divid [题目类型]点在多边形内 &题解: 蓝书274, 感觉我的代码和刘汝佳的没啥区别,可是我的就是wa,所以贴一发刘汝佳 ...

  9. uva 10256 The Great Divide

    题意:给定两个点集,一个红点集,另一个蓝点集,询问,能否找到一条直线能,使得任取一个红点和蓝点都在直线异侧. 思路:划分成两个凸包,一个红包,一个蓝包.两个凸包不相交不重合. 1.任取一个凸包中的点不 ...

随机推荐

  1. (hdu)5547 Sudoku (4*4方格的 数独 深搜)

    Problem Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game ...

  2. Google Test Frame 简单使用例子

    1 序言——为什么折腾Google Test 被逼无奈的. 最近研究google开源的基于列存储的数据库查询引擎supersonic源码.初略的浏览了一遍代码,竟然没有main函数,顿时惊讶的目瞪口呆 ...

  3. nagios 完全配置手册

    Linux下Nagios的安装与配置   一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机 ...

  4. input表单

    submit:点击submit按钮表单就会被提交给服务器,中文IE下默认按钮文本为“提交查询”,可以设置value属性修改按钮的显示文本 text:size属性为宽度,value为值,maxlengt ...

  5. 关于APlayer播放器在打包安装后提示“没有注册类”的解决办法

    1.首先需要确定必要的DLL文件都已经在正确的安装目录下了: 2.项目中引用的DLL必须是Debug目录下的: 3.若后续修改或者重新注册了APlayer组件,那么所有的DLL都需要替换成最新的. 关 ...

  6. mongodb数据库操作--备份 还原 导出 导入

    首先数据库备份: mongodump -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -o 文件存在路径  mongodump -h 127.0.0.1 -u admin -p ...

  7. Python学习_数据处理split方法

    用open方法导入文件“sketch.txt”后,用split()方法进行分割: >>> import os >>> os.chdir('C:/Python33/H ...

  8. 斗地主你什么时候才会托管?(.NET中的托管于非托管)

    文章部分引自<.NET4.0面向对象编程漫谈(基础篇)>第1章.NET面向对象编程基础(作者:金旭亮) 无意间看到一位四五岁左右小朋友在玩斗地主,总开始到结束,她一直都在使用“提示”(托管 ...

  9. HDU 1166 敌兵布阵 线段树的基本应用——动态区间和问题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=1166 简单题,1A了,这个好像就是传说中的“点树”. 设当前结点表示线段[left, right],编号 ...

  10. css实现网页布局随滚轮变化响应移动

    _position:absolute; _top:expression(eval(document.documentElement.scrollTop)); 1.第一句代码 _position:abs ...