[codeforces]166B
来源:互联网 发布:网络剧 余罪 沈嘉文 编辑:程序博客网 时间:2024/04/30 21:56
ime limit per test : 2 seconds
memory limit per test : 256 megabytes
You’ve got another geometrical task. You are given two non-degenerate polygons A and B as vertex coordinates. Polygon A is strictly convex. Polygon B is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.
Your task is to check whether polygon B is positioned strictly inside polygon A. It means that any point of polygon B should be strictly inside polygon A. “Strictly” means that the vertex of polygon B cannot lie on the side of the polygon A.
Input
The first line contains the only integer
The next line contains a single integer
The coordinates of the polygon’s vertices are separated by a single space. It is guaranteed that polygons A and B are non-degenerate, that polygon A is strictly convex, that polygon B has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line.
Output
Print on the only line the answer to the problem — if polygon B is strictly inside polygon A, print “YES”, otherwise print “NO” (without the quotes).
Input1
6-2 10 33 34 13 -22 -240 12 23 11 0
Output1
YES
Input2
51 24 23 -3-2 -2-2 140 11 24 12 -1
Output2
NO
Input3
5-1 22 34 13 -20 -351 01 13 15 -12 -1
Output3
NO
题意:
给一个n个顶点的凸多边形A和一个m个顶点的凸多边形B,判断B是否在A内
NOTE:
B的顶点不能在A的点或者边上
题解:
先将凸多边形A的所有点按照极角排序,然后对于每一个B的顶点,我们只需要判断其是否在A中就可推知凸多边形B是否在A中。那么对于每一个B的定点
#include<bits/stdc++.h>#define LiangJiaJun main#define ll long longusing namespace std;int n,m;struct Vex{ ll x,y;}pa[100004],pb[20004];ll operator*(Vex A,Vex B){return A.x*B.y-A.y*B.x;}Vex operator-(Vex A,Vex B){ Vex t; t.x=A.x-B.x; t.y=A.y-B.y; return t;}ll dis(Vex A,Vex B){return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);}inline bool dex(Vex A,Vex B){ ll sv = (A-pa[1])*(B-pa[1]); if(sv == 0)return dis(A,pa[1])<dis(B,pa[1]); return sv<0;}int For_unc(Vex G){ int l=2,r=n,ans=-1; while(l<=r){ int mid=(l+r)>>1; if((G-pa[1])*(pa[mid]-pa[1]) <= 0){ ans=mid;r=mid-1; } else l=mid+1; } return ans;}int LiangJiaJun(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%I64d%I64d",&pa[i].x,&pa[i].y); scanf("%d",&m); for(int i=1;i<=m;i++)scanf("%I64d%I64d",&pb[i].x,&pb[i].y); int t=1; for(int i=1;i<=n;i++) if(pa[i].y<pa[t].y||(pa[i].y==pa[i].y&&pa[i].x<pa[t].x))t=i; swap(pa[1],pa[t]); sort(pa+2,pa+n+1,dex); for(int i=1;i<=m;i++){ int st=For_unc(pb[i]); if(st==2)return puts("NO"),0; Vex Gr = pa[st],Gl=pa[st-1]; if((pb[i]-Gl)*(Gr-Gl)<=0)return puts("NO"),0; if(st-1==2){ if((Gl-pa[1])*(pb[i]-pa[1])==0)return puts("NO"),0; } if(st==m){ if((Gr-pa[1])*(pb[i]-pa[1])==0)return puts("NO"),0; } } puts("YES"); return 0;}
- Codeforces 166B - Polygons
- codeforces 166 B. Polygons
- [codeforces]166B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 166B(凸包)
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- codeforces 214B Hometask
- Failed to decode response: zlib_decode(): data error
- 对软件测试的认识
- 求助
- TCP协议 三次握手以及四次挥手
- VIP Load Balance via iptables on Linux
- [codeforces]166B
- 取近似值
- Java之简单的泛型
- 新手村 Boss站-入门综合练习2 Function
- 操作系统学习-2. 操作系统的基本特性与主要功能
- peewee模块操作mysql数据库
- 合并表记录
- 安装Windows系统
- 广义离散卷积定理——离散傅里叶卷积定理的推广