模板敲错了于是WA了好几遍……

判断由红点和蓝点分别组成的两个凸包是否相离,是输出Yes,否输出No。

训练指南上的分析:

1.任取红凸包上的一条线段和蓝凸包上的一条线段,判断二者是否相交。如果相交(不一定是规范相交,有公共点就算相交),则无解

2.任取一个红点,判断是否在蓝凸包内。如果是,则无解。蓝点红凸包同理。

其中任何一个凸包退化成点或者线段时需要特判。

其实只需要把上面两个判断顺序颠倒一下,就可以不需要特判。

先判断点是否在凸包内,因为这个考虑了点在凸包边界上的情况,所以后面判凸包线段是否相交时直接用规范相交判断即可。

此时特殊情况包含在了上两种情况中,因此不需要特判。

 #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int MAXN = ; const double eps = 1e-; struct Point
{
double x, y;
Point( double x = , double y = ):x(x), y(y) { }
}; typedef Point Vector; Vector operator+( Vector A, Vector B ) //向量加
{
return Vector( A.x + B.x, A.y + B.y );
} Vector operator-( Vector A, Vector B ) //向量减
{
return Vector( A.x - B.x, A.y - B.y );
} Vector operator*( Vector A, double p ) //向量数乘
{
return Vector( A.x * p, A.y * p );
} Vector operator/( Vector A, double p ) //向量数除
{
return Vector( A.x / p, A.y / p );
} bool operator<( const Point& A, const Point& B ) //两点比较
{
return A.x < B.x || ( A.x == B.x && A.y < B.y );
} int dcmp( double x ) //控制精度
{
if ( fabs(x) < eps ) return ;
else return x < ? - : ;
} bool operator==( const Point& a, const Point& b ) //两点相等
{
return dcmp( a.x - b.x ) == && dcmp( a.y - b.y ) == ;
} double Dot( Vector A, Vector B ) //向量点乘
{
return A.x * B.x + A.y * B.y;
} double Length( Vector A ) //向量模
{
return sqrt( Dot( A, A ) );
} double Angle( Vector A, Vector B ) //向量夹角
{
return acos( Dot(A, B) / Length(A) / Length(B) );
} double Cross( Vector A, Vector B ) //向量叉积
{
return A.x * B.y - A.y * B.x;
} double Area2( Point A, Point B, Point C ) //向量有向面积
{
return Cross( B - A, C - A );
} Vector Rotate( Vector A, double rad ) //向量旋转
{
return Vector( A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad) );
} Vector Normal( Vector A ) //向量单位法向量
{
double L = Length(A);
return Vector( -A.y / L, A.x / L );
} Point GetLineIntersection( Point P, Vector v, Point Q, Vector w ) //两直线交点
{
Vector u = P - Q;
double t = Cross( w, u ) / Cross( v, w );
return P + v * t;
} double DistanceToLine( Point P, Point A, Point B ) //点到直线的距离
{
Vector v1 = B - A, v2 = P - A;
return fabs( Cross( v1, v2 ) ) / Length(v1);
} double DistanceToSegment( Point P, Point A, Point B ) //点到线段的距离
{
if ( A == B ) return Length( P - A );
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if ( dcmp( Dot(v1, v2) ) < ) return Length(v2);
else if ( dcmp( Dot(v1, v3) ) > ) return Length(v3);
else return fabs( Cross( v1, v2 ) ) / Length(v1);
} Point GetLineProjection( Point P, Point A, Point B ) // 点在直线上的投影
{
Vector v = B - A;
return A + v*( Dot(v, P - A) / Dot( v, v ) );
} 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 OnSegment( Point p, Point a1, Point a2 ) //点在线段上,不包含端点
{
return dcmp( Cross(a1 - p, a2 - p) ) == && dcmp( Dot( a1 - p, a2 - p ) ) < ;
} double toRad( double deg ) //角度转弧度
{
return deg / 180.0 * acos( -1.0 );
} int ConvexHull( Point *p, int n, Point *ch ) //求凸包
{
sort( p, p + n );
n = unique( p, p + n ) - p;
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;
} int isPointInPolygon( Point p, Point *poly, int n ) //判断一点是否在凸包内
{
int wn = ; for ( int i = ; i < n; ++i )
{
Point& p1 = poly[i], p2 = poly[ (i + )%n ];
if ( p == p1 || p == p2 || OnSegment( 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 ; //外部
} double PolygonArea( Point *p, int n ) //多边形有向面积
{
double area = ;
for ( int i = ; i < n - ; ++i )
area += Cross( p[i] - p[], p[i + ] - p[] );
return area / 2.0;
} bool checkConvexHullIntersection( Point *a, Point *b, int na, int nb )
{
for ( int i = ; i < na; ++i )
if ( isPointInPolygon( a[i], b, nb ) ) return true; for ( int i = ; i < nb; ++i )
if ( isPointInPolygon( b[i], a, na ) ) return true; for ( int i = ; i < na; ++i )
for ( int j = ; j < nb; ++j )
if ( SegmentProperIntersection(a[i], a[ (i + ) % na ], b[j], b[ (j + ) % nb ] ) ) return true; return false;
} Point M[MAXN], chM[MAXN];
Point C[MAXN], chC[MAXN]; int main()
{
int Mn, Cn;
while ( scanf( "%d%d", &Mn, &Cn ), Mn || Cn )
{
for ( int i = ; i < Mn; ++i )
scanf( "%lf%lf", &M[i].x, &M[i].y ); for ( int i = ; i < Cn; ++i )
scanf( "%lf%lf", &C[i].x, &C[i].y ); int Mcnt = ConvexHull( M, Mn, chM );
int Ccnt = ConvexHull( C, Cn, chC ); if ( checkConvexHullIntersection( chM, chC, Mcnt, Ccnt ) ) puts("No");
else puts("Yes");
}
return ;
}

UVa 10256 - The Great Divide 判断凸包相交的更多相关文章

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

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

  2. POJ 3805 Separate Points (判断凸包相交)

    题目链接:POJ 3805 Problem Description Numbers of black and white points are placed on a plane. Let's ima ...

  3. HDU 6590 Code (判断凸包相交)

    2019 杭电多校 1 1013 题目链接:HDU 6590 比赛链接:2019 Multi-University Training Contest 1 Problem Description Aft ...

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

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

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

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

  6. uva 10256 The Great Divide

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

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

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

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

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

  9. UVALive7461 - Separating Pebbles 判断两个凸包相交

    //UVALive7461 - Separating Pebbles 判断两个凸包相交 #include <bits/stdc++.h> using namespace std; #def ...

随机推荐

  1. advance 模板 怎么生成module

    advance 模板 怎么生成module namespace写什么如果是前台呢就是 frontend\modules\modulename\Module@我叫红领巾 module id有什么用bak ...

  2. C++实现glut绘制点、直线、多边形、圆

    C++实现glut绘制点.直线.多边形.圆 必备环境 glut.h 头文件 glut32.lib 对象文件库 glut32.dll 动态连接库 程序说明 C++实现了用glut画点.画直线.画多边形和 ...

  3. Animations--动画基础

    基础动画 //1.在0.5s内,将_field.alpha 的数值变为1.0 [UIView animateWithDuration:0.5 animations:^{ _field.alpha = ...

  4. 0x03伪指令

    等号伪指令 = 相当于指定常量,由等号定义的符号常量不占用存储空间. count = 1234 可以重复定义多次,EQU则不容许 EQU伪指令 1.常量名 EQU 表达式 NUMBER EQU 10* ...

  5. VS查看工程项目代码行数

    ctrl+shift+F  查找选项选正则表达式  正则表达式 b*[^:b#/]+.*$或 ^b*[^:b#/]+.*$

  6. JPA学习---第五节:日期和枚举等字段类型的JPA映射

    1.在上一节可在数据库中看到创建出来的表和字段,是通过 Entity bean 来创建的,而创建表名和字段名的规则是怎样的? 有类,代码如下: package learn.jpa.bean; impo ...

  7. c语言编程之循环队列

    利用链表实现的循环队列,完成了队列的入队和出队,对于队空和队满用了一个flag进行标记.入队flag++,出队flag-- #include"stdio.h" typedef in ...

  8. [搜片神器]使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)

    谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器:http://www.sosobta.com   大家可以给提点意见... 出售商业网站代码,万元起,非诚勿扰,谢谢. 联系h31h31 a ...

  9. 工程移除CocoaPods依赖库

    http://zanderzhang.gitcafe.io/2015/09/26/工程移除CocoaPods依赖库/ 点这里--->CocoaPods安装和使用教程 当我们工程安装很多第三方开源 ...

  10. C++排序函数sort/qsort使用

    问题描述:        C++排序函数sort/qsort的使用 问题解决:           (1)sort函数使用   注:           sort函数,参数1为数组首地址,参数2是数组 ...