UVA 10256 The Great Divide 凸包 .
来源:互联网 发布:vb调用大漠 编辑:程序博客网 时间:2024/05/17 04:30
题目地址:https://vjudge.net/problem/UVA-10256
红点做一个凸包,蓝点做一个凸包,要判断他们之间能由直线隔开,也就是没有相交
有两种情况要注意:
所以
1两个凸包上任意两个线段不想交
2凸包上任意一个点不存在另一个凸包内部
#include <bits/stdc++.h>using namespace std;#define REP(i,a,b) for(int i=a;i<=(int)(b);++i)#define REPD(i,a,b) for(int i=a;i>=(int)(b);--i)const double PI=acos(-1);const double EPS=1e-6;int dcmp(double x){if(fabs(x)<EPS) return 0;return x > 0 ? 1 : -1;}struct Point{double x,y;};typedef Point Vector;bool operator < (const Point& p1, const Point& p2){return p1.x<p2.x || (p1.x==p2.x && p1.y<p2.y) ;}Vector operator / (const Point& A, double x){return Vector{A.x/x, A.y/x};}Vector operator * (const Vector& A, double x){return Vector{A.x*x, A.y*x};}Vector operator - (const Vector& A, const Vector& B){return Vector{A.x-B.x,A.y-B.y};}Vector operator + (const Point& A, const Vector& v){return Point{A.x+v.x,A.y+v.y};}Vector Rotate(const Point& p,double ang){return Vector{p.x*cos(ang)-p.y*sin(ang),p.x*sin(ang)+p.y*cos(ang)};}double Cross(const Vector& A, const Vector& B){return A.x*B.y-A.y*B.x;}double Dot(Vector A, Vector B){return A.x*B.x+A.y*B.y;}double Length(Vector v){return sqrt(fabs(Dot(v,v)));}Vector Unit(Vector v){return v/Length(v);}const int maxn=500+5;Point M[maxn],C[maxn],Mch[maxn],Cch[maxn];int convexHull(Point* A, int n, Point* sol){sort(A,A+n);int m=0;REP(i,0,n-1){while(m>1 && dcmp( Cross(sol[m-1]-sol[m-2], A[i]-sol[m-1])) <= 0) m--;sol[m++]=A[i];}int k=m;REPD(i,n-2,0){while(m>k && dcmp( Cross(sol[m-1]-sol[m-2], A[i]-sol[m-1])) <= 0) m--;sol[m++]=A[i];}if(n>1) m--;return m;}bool OnSegment(Point p, Point A, Point B){return dcmp(Cross(A-p, B-p))==0 && dcmp(Dot(A-p, B-p))<=0;}bool isIntersection(Point p1, Point p2, Point p3, Point p4){if(OnSegment(p1,p3,p4)||OnSegment(p2,p3,p4)||OnSegment(p3,p1,p2)||OnSegment(p4,p1,p2)) return true;double c1=Cross(p2-p1,p3-p1), c2=Cross(p2-p1,p4-p1), c3=Cross(p4-p3,p1-p3), c4=Cross(p4-p3,p2-p3); return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;}bool isPointInPolygon(Point A, Point* poly, int n){int wn=0;REP(i,0,n-1){int k=dcmp(Cross(poly[(i+1)%n]-poly[i], A-poly[i]));double d1=poly[i].y-A.y;double d2=poly[(i+1)%n].y-A.y;if(k>0 && dcmp(d1)<=0 && dcmp(d2)>0) wn++;if(k<0 && dcmp(d2)<=0 && dcmp(d1)>0) wn--;}if(wn!=0) return true;return false;}int main(int argc, char const *argv[]){// freopen("input.in","r",stdin);int m,c;while(scanf("%d %d",&m,&c)==2&&m+c){REP(i,0,m-1) scanf("%lf%lf",&M[i].x,&M[i].y);REP(i,0,c-1) scanf("%lf%lf",&C[i].x,&C[i].y);int mCnt=convexHull(M,m,Mch);int cCnt=convexHull(C,c,Cch);bool ok=true;REP(i,0,mCnt-1) {REP(j,0,cCnt-1) if(isIntersection(Mch[i],Mch[(i+1)%mCnt],Cch[j],Cch[(j+1)%cCnt])) { ok=false; break; }if(!ok) break;}if(ok) {REP(i,0,mCnt-1){REP(j,0,cCnt-1) if(isPointInPolygon(Mch[i],Cch,cCnt)) {ok=false; break; }if(!ok) break;} }if(ok) {REP(i,0,cCnt-1){REP(j,0,mCnt-1) if(isPointInPolygon(Cch[i],Mch,mCnt)) {ok=false; break; }if(!ok) break;} }printf("%s\n", ok?"Yes":"No");}return 0;}
0 0
- UVA 10256 The Great Divide 凸包
- UVA 10256 The Great Divide 凸包 .
- UVa 10256 The Great Divide 凸包, 凸包分离
- UVA 10256 The Great Divide(凸包应用)
- uva 10256 - The Great Divide(凸包)
- Uva 10256 The Great Divide(凸包)
- UVA 10256 The Great Divide
- UVA 10256 - The Great Divide
- UVA 10256 The Great Divide
- UVA 10256 The Great Divide
- uva 10256 The Great Divide
- UVa 10256 The Great Divide,判断两个凸包是否相离
- UVA 10256 The Great Divide(凸包应用 即凸包+线段相交判定+点是否在凸包内判断)
- uva10256 The Great Divide(凸包+判断)
- uva10256 The Great Divide
- Fixing the Great Wall UVA
- Fixing the Great Wall UVA
- Uva-1045-The Great Wall Game
- poj 2396 Budget (有源汇有上下界的网络流)
- java自增自减运算符
- 尹成版本汉诺塔递归和高级递归
- 过滤器和拦截器的区别
- ubuntu下安装lamp环境
- UVA 10256 The Great Divide 凸包 .
- Bare.Bones.Software.BBEdit.v11.6.3.MacOSX.Incl.Keymaker-ARN
- 判断单链表是否有环
- Debian 8.0桌面系统root用户登录和root用户自动登录
- 3D里面的旋转
- PHPExcel插件的使用1——基本数据导出
- SQL 语言分类
- CSS3--多列
- 改善 jdbc和tomcat对中文的支持