The Great Divide

Input: standard input

Output: standard output

Time Limit: 8 seconds

Memory Limit: 32 MB

Somewhere in Gaul, there is a little village very like the village where Asterix and Obelix live. Not very long ago they had only one chief Altruistix and peace reigned in the village. But now those happy days are just dreams. The villagers are now divided. Some of the villagers have elected Majestix as their chief and the others have elected Cleverdix.

                        

Majestix                                             Cleverdix

The two chiefs have decided to divide the village into two parts by digging a straight ditch through the middle of the village so that the houses of the supporters of Majestix lie on one part and those of the followers of Cleverdix lie on the other. So, they have invitedGetafix, the venerable druid of Asterix’s village, to figure out whether such a dividing line exists or not.

Getafix

Since Getafix knows that you are so good in programming, he seeks your help.

 

Input

The input may contain multiple test cases.

The first line of each test case contains two integers M and C (1 £ M, C £ 500), indicating the number of houses of the supporters ofMajestix and Cleverdix respectively.

Each of the next M lines contains two integers x and y (-1000 £ x, y £ 1000) giving the co-ordinates of the house of a supporter ofMajestix. For convenience each house is considered as a single point on the plane.

Each of the next C lines contains two integers x and y (-1000 £ x, y £ 1000) giving the co-ordinates of the house of a supporter ofCleverdix.

The input will terminate with two zeros for M and C.

Output

For each test case in the input output a line containing either “Yes” or “No” depending on whether there exists a straight line that divides the two set of houses. The dividing line can NOT contain points of both sides.

 

Sample Input

4 3

100 600

200 400

600 500

300 700

400 100

600 200

500 300

4 3

100 600

400 100

600 200

500 300

200 400

600 500

300 700

0 0

 

Sample Output

Yes

No

判断两个点集是否相交,即有没有一条线段可以划分两个点集。

先求出凸包。

判断凸包中是否有一点在另一个凸包内。

判断凸包内是否有任意两条线段相交。

注意下,按坐标排序的时候要用dcmp来写。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = ;
const double eps = 1e- ;
int n1 , n2 ; int dcmp( double x ) { if( fabs(x)<eps) return ; return x<?-:;} struct Point {
double x , y ;
Point(){};
Point( double a, double b ) { x=a ,y=b; }
bool operator < ( const Point &a ) const {
return dcmp(x-a.x)< ||(dcmp(x-a.x)== && dcmp(y-a.y)<);
} }p1[N],p2[N],ch1[N],ch2[N];
Point operator - ( Point a , Point b ) {
return Point(a.x-b.x,a.y-b.y);
}
Point operator + ( Point a , Point b ) {
return Point(a.x+b.x,a.y+b.y);
}
double Cross( Point a , Point b ) { return a.x*b.y-a.y*b.x; }
double Dot( Point a , Point b ) { return a.x*b.x+a.y*b.y; } //test bool isPointOnSegment( Point p , Point a1 , Point a2 ) {
return dcmp( Cross(a1-p,a2-p)) == && dcmp(Dot(a1-p,a2-p)) < ;
} bool SegmentProperIntersection(Point a1 , Point a2 , Point b1 , Point 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 isPointInPolygon( Point p , Point* poly , int n ) {
int wn = ;
for( int i = ; i < n ; ++i ) {
if( isPointOnSegment( p , poly[i] , poly[(i+)%n] ) ) return true;
int k = dcmp( Cross( poly[(i+)%n]-poly[i] , p - poly[i] ) );
int d1 = dcmp( poly[i].y - p.y );
int d2 = dcmp( poly[(i+)%n].y - p.y );
if( k > && d1<= && d2 > ) wn++ ;
if( k < && d2 <= && d1 > ) wn--;
}
if( wn != ) return true; // inside
return false; //outside
}
int ConvexHull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
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--;
return m;
}
void Run() {
for( int i = ; i < n1 ; ++i ){
scanf("%lf%lf",&p1[i].x,&p1[i].y);
}
for( int i = ; i < n2 ; ++i ){
scanf("%lf%lf",&p2[i].x,&p2[i].y);
}
int m1 = ConvexHull(p1,n1,ch1), m2 = ConvexHull(p2,n2,ch2);
for( int i = ; i < m1 ; ++i )
if( isPointInPolygon(ch1[i],ch2,m2) ) { puts("No"); return ;}
for( int i = ; i < m2 ; ++i )
if( isPointInPolygon(ch2[i],ch1,m1) ) { puts("No"); return ;}
for( int i = ; i < m1 ; ++i ) {
for( int j = ; j < m2 ; ++j ){
if( SegmentProperIntersection( ch1[i],ch1[(i+)%m1],ch2[j],ch2[(j+)%m2]) ){
puts("No"); return ;
}
}
}
puts("Yes");
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
while( scanf("%d%d",&n1,&n2) == && n1 )Run();
}

UVA 10256 The Great Divide(凸包划分)的更多相关文章

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

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

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

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

  3. UVA 10256 The Great Divide (凸包,多边形的位置关系)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34148 [思路] 凸包 求出红蓝点的凸包,剩下的问题就是判断两个凸 ...

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

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

  5. uva 10256 The Great Divide

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

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

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

  7. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  8. 【暑假】[数学]UVa 10375 Choose and divide

    UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...

  9. UVa 10256 凸包简单应用

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. Pull Request的正确打开方式(如何在GitHub上贡献开源项目)

    Pull Request的正确打开方式(如何在GitHub上贡献开源项目) GitHub的官方帮助如下: Fork A Repo: https://help.github.com/articles/f ...

  2. CSS 针对谷歌浏览器(Chrome) safari的webkit核心浏览器CSS hack

    @media screen and (-webkit-min-device-pixel-ratio:0) { ul#navUL ul a{padding:8px 2px;word-break:keep ...

  3. 2019-9-2-win10-UWP-MvvmLight入门

    title author date CreateTime categories win10 UWP MvvmLight入门 lindexi 2019-09-02 12:57:38 +0800 2018 ...

  4. macos Item2 添加 Shell Integration (ftp传输)

    macos系统 的item2软件 的  Shell Integration (ftp传输)  功能强大,无需 安装其他ftp软件,也是为了保证 密码安全 在使用时报错如下(因为本地 ping不通): ...

  5. K8S创建的相关yaml文件

    一.K8S-yaml的使用及命令 YAML配置文件管理对象 对象管理: # 创建deployment资源 kubectl create -f nginx-deployment.yaml # 查看dep ...

  6. Java疯狂讲义笔记——内部类

    [定义]内部类:定义在其它类内部的类.外部类:包含内部类的类,也称 宿主类.局部内部类:定义在方法里的内部类. [接口内部类]接口中也可以定义内部类,必须为public static修饰(自动添加), ...

  7. 【LeetCode】图论 graph(共20题)

    [133]Clone Graph (2019年3月9日,复习) 给定一个图,返回它的深拷贝. 题解:dfs 或者 bfs 都可以 /* // Definition for a Node. class ...

  8. Git最全总结

    一个小时学会Git   目录 一.版本控制概要 工作区 暂存区 本地仓库 远程仓库 1.1.什么是版本控制 1.2.常用术语 1.3.常见的版本控制器 1.4.版本控制分类 1.4.1.本地版本控制 ...

  9. tomcat启动一闪而过解决办法报错The CATALINA_HOME environment variable is not defined correctly

    解决办法: Tomcat无论在windows上还是Linux上只需要吧安装包传上去解压就行,不需要配置环境变量,吧之前有可能别人别配置的环境变量统一删掉即可(网上一大堆说需要配置的都是胡说八道).把以 ...

  10. linux根据进程名获取PID

    经常需要Kill多个进程,这些进程包含共同的关键字,可以用一条命令Kill掉它们. ps aux | grep "common" |grep -v grep| cut -c 9-1 ...