模板敲错了于是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. 转字符驱动实例gpio

    概述: 字符设备驱动程序: 是按照字符设备要求完成的由操作系统调用的代码. 重点理解以下内容:  1. 驱动是写给操作系统的代码,它不是直接给用户层程序调用的,而是给系统调用的  2. 所以驱动要向系 ...

  2. 【http】生命周期和http管道技术 整理中

    httpModules 与 httpHandlers  正在写demo public class Httpext : IHttpModule { public void Dispose() { thr ...

  3. kendo ui template的用法

    kendo ui template的用法: Kendo UI 框架提供了一个易用,高性能的JavaScript模板引擎.通过模板可以创建一个HTML片段然后可以和JavaScript数据合并成最终的H ...

  4. Java加解密与数字签名

    ** Java加解密 ** 实现方式:JDK实现,CC,BC JDK提供比较基础的底层的实现:CC提供一些简化的操作:BC提供补充 一.Base64加密 非常简单,加密解密就一个函数. 代码如下: 二 ...

  5. Build Settings

    Add Open Scenes 选择一个关卡,使其处于打开状态,在菜单栏选择 File -> Build Settings 打开Build Settings窗口.选择 Add Open Scen ...

  6. final ,override关键字

    final 有时我们会定义这样一种类,我们不希望其他类继承它,或者不想考虑它是否适合作为一个基类.为了实现这一目的,c++ 11新标准提供了一种防止继承发生的方法,即在类名后跟一个关键字final: ...

  7. phpcms v9后台登陆验证码无法显示,怎么取消验证码

    phpcms v9后台登陆验证码无法显示论坛里关于这个问题貌似一直没有解决,查看源代码后发现,关键一点是获取验证码的图片与全局变量SITE_URL相关,也就是网站的目录, 所以只要修改cache/co ...

  8. Careercup - Google面试题 - 5735304249999360

    2014-05-03 23:18 题目链接 原题: Insert a element in a sorted circular linked list 题目:题意简单明了,向一个有序的循环单向链表中插 ...

  9. HDU 1423 Greatest Common Increasing Subsequence LCIS

    题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  10. [转载]C#中字典集合的两种遍历

    Dictionary<string, string> dictionary = new Dictionary<string,string>(); foreach (string ...