Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包
2 seconds
256 megabytes
standard input
standard output
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.
The first line contains the only integer n (3 ≤ n ≤ 105) — the number of vertices of polygon A. Then n lines contain pairs of integers xi, yi (|xi|, |yi| ≤ 109) — coordinates of the i-th vertex of polygon A. The vertices are given in the clockwise order.
The next line contains a single integer m (3 ≤ m ≤ 2·104) — the number of vertices of polygon B. Then following m lines contain pairs of integers xj, yj (|xj|, |yj| ≤ 109) — the coordinates of the j-th vertex of polygon B. The vertices are given in the clockwise order.
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.
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).
6
-2 1
0 3
3 3
4 1
3 -2
2 -2
4
0 1
2 2
3 1
1 0
YES
5
1 2
4 2
3 -3
-2 -2
-2 1
4
0 1
1 2
4 1
2 -1
NO
5
-1 2
2 3
4 1
3 -2
0 -3
5
1 0
1 1
3 1
5 -1
2 -1
NO
题意:给你两个多边形A,B,已知A为凸多边形,问B是否全部在A内(严格);
思路:将所有点合并,查找凸包,求是否B上的点都不在凸包上;
因为有一个严格的要求,对于扫描法的凸包,不一定可以找到相同斜率的点;
对于Andrew求凸包 ,只删除一些点,使得形成凸包;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
#define LL long long #define bug(x) cout<<"bug"<<x<<endl;
const int N=2e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+;
const double eps=(1e-),pi=(*atan(1.0)); int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
Point() {}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x= tx*cos(B) - ty*sin(B);
y= tx*sin(B) + ty*cos(B);
}
bool operator <(const Point p)const
{
if(x!=p.x)
return x<p.x;
return y<p.y;
}
};
struct Line
{
Point s,e;
Line() {}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
//两直线相交求交点 //第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交 //只有第一个值为2时,交点才有意义
pair<int,Point> operator &(const Line &b)const
{
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == )
{
if(sgn((s-b.e)^(b.s-b.e)) == ) return make_pair(,res);//重合
else return make_pair(,res);//平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(,res);
}
}; double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
const int MAXN = ;
Point listt[MAXN];
int Stack[MAXN],top; int convexhull(int n) /*建立凸包*/
{
sort(listt,listt+n);
int m=;
for(int i=; i<n; i++) {
while(m> && sgn((listt[Stack[m-]]-listt[Stack[m-]])^(listt[i]-listt[Stack[m-]]))<)
m--;
Stack[m++]=i;
}
int k=m;
for(int i=n-; i>=; i--) {
while(m>k && sgn((listt[Stack[m-]]-listt[Stack[m-]])^(listt[i]-listt[Stack[m-]]))<)
m--;
Stack[m++]=i;
}
if(n>) m--;
return m;
}
set<Point>s;
int n,m;
int FIND()
{
//for(int i=0;i<top;i++)
//cout<<listt[Stack[i]].x<<" "<<listt[Stack[i]].y<<endl;
for(int i=;i<top;i++)
if(s.find(listt[Stack[i]])!=s.end())return ;
return ;
}
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
double x,y;
scanf("%lf%lf",&x,&y);
listt[i]=Point(x,y);
}
scanf("%d",&m);
for(int i=;i<m;i++)
{
double x,y;
scanf("%lf%lf",&x,&y);
listt[i+n]=Point(x,y);
s.insert(listt[i+n]);
}
top=convexhull(n+m);if(FIND())printf("NO\n");
else printf("YES\n");
return ;
}
Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包的更多相关文章
- Codeforces Round #113 (Div. 2)
Codeforces Round #113 (Div. 2) B. Polygons 题意 给一个\(N(N \le 10^5)\)个点的凸包 \(M(M \le 2 \cdot 10^4)\)次询问 ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- Codeforces Round #113 (Div. 2) Tetrahedron(滚动DP)
Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)
https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...
- C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块
C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #364 (Div. 2) C 二分处理+求区间不同字符的个数 尺取法
C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]
B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #620 (Div. 2)E(LCA求树上两点最短距离)
LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES ...
- Codeforces Round #532 (Div. 2) 题解
Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...
随机推荐
- F#周报2019年第6期
新闻 应用F#挑战活动 Visual F#:锁定VS 2019正式版本 Visual F#:VS 2019工具性能 ML.NET 0.10发布 F# eXchange 2019即将来临 Visual ...
- Luogu 1098 - 字符串的展开 - [字符串操作][模拟]
题目链接:https://www.luogu.org/problemnew/show/P1098 题目描述在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中 ...
- 关于SQL Server将一列的多行内容拼接成一行的问题讨论【转】
原文链接:https://blog.csdn.net/rolamao/article/details/7745972 比如表中有两列数据 : ep_classes ep_name AAA ...
- 20190404 Oracle忘记登陆密码
记忆力不好,总是忘记Oracle账号的登陆密码 修改方式 Windows cmd 登陆修改后的密码即可
- Vue脚手架使用步骤 2.9.6版本
转载自:https://blog.csdn.net/sky_LQ/article/details/80729547 Vue脚手架使用步骤 2018年06月19日 12:10:35 sky_LQ 阅读数 ...
- element-ui table表格展开行每次只能展开一行
https://www.jianshu.com/p/a59c22202f2c <template> <el-table @expand-change="expandSele ...
- vue项目搭建步骤
https://blog.csdn.net/echo008/article/details/77099058 https://blog.csdn.net/echo008/article/details ...
- [js]js设计模式-构造函数模式
构造函数模式 function WriteJsPerson(name,age) { this.name=name; //不用手动创建obj this.age = age; this.writeJs=f ...
- 谷歌PM面试官告诉你,如何成功拿到理想offer
快来看看大咖Nick如何甄选人才~文章转自墨刀公众号. 本文作者: Nick Baum,目前在谷歌做PM 作为谷歌的产品经理和面试官,我已经面过几百个PM的候选人了吧.这些经历能让我分享一下在PM求职 ...
- 如果merge分支出现问题,使用git方式查看日志
Administrator@IT-20161115IKEG MINGW32 ~$ cd e: Administrator@IT-20161115IKEG MINGW32 /e$ ls$RECYCLE. ...