题目链接: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. Cogs 1298.通讯问题

    1298.通讯问题 ★ 输入文件:jdltt.in 输出文件:jdltt.out 简单对比 时间限制:1 s 内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员,每个队员都有联系方式(如电 ...

  2. Oracle 10g 下载地址

    Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...

  3. C++11中新特性之:initializer_list详解

    C++11提供的新类型,定义在<initializer_list>头文件中. template< class T > class initializer_list; 先说它的用 ...

  4. jQuery 快速入门教程

    内容目录 jQuery 入门 什么是jQuery 如何使用jQuery jQuery的运行原理 如何选择jQuery版本 ready() 准备就绪时执行代码 jQuery 核心:选取元素 使用jQue ...

  5. 系统监控的一些工具w , vmstat

    w 命令:--w 查看的是系统整体上的负载 # w 15:23:46 up 3:34, 2 users, load average: 0.03, 0.05, 0.00 USER TTY FROM LO ...

  6. jquery.maskload.js学习笔记

    概述 Loadmask是一个jquery plugin,使用此插件可以在DOM元素加载或更改内容时为此DOM元素添加一个屏蔽层,以防止用户互动,同时起到提醒用户后台任务正在运行的作用. 使用此插件可以 ...

  7. Common Configration实验

      用了一个CombinedConfigration 来做属性文件的继承(套用)发现它是以先添加的ConfigureRation作为最终输出也就是如果要实现我们项目中的效果 需要从内层目录向外层目录逐 ...

  8. 查看 MySQL 数据库中每个表占用的空间大小

    TABLE_SCHEMA : 数据库名TABLE_NAME:表名ENGINE:所使用的存储引擎TABLES_ROWS:记录数DATA_LENGTH:数据大小INDEX_LENGTH:索引大小 SELE ...

  9. Windows下MySQL数据库备份脚本(二)

    说明: MySQL数据库安装目录:C:\Program Files\MySQL\MySQL Server 5.0 MySQL数据库存放目录:C:\Program Files\MySQL\MySQL S ...

  10. WPF界面特殊字符处理

          界面XAML不支持< .>.&."等字符. 使用字符实体编码进行替代,以下是pro WPF 4.5的摘要表 Special Character        ...