CodeForces 166B (凸包)
求一个多边形是否完全在另一个凸多边形内。
乍一看,好像要判点在多边形内,但复杂度不允许,仔细一想,可以把两个多边形的点混起来求一个共同的凸包,如果共同的凸包依旧是原来凸包上的点,说明是。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 200010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
int flag;
point(double x=,double y=):x(x),y(y){}
}p[N],ch[N],q[N];
typedef point pointt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
double mul(point a,point b,point c)
{
return cross(b-a,c-a);
}
double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
bool cmp(point a,point b)
{
if(mul(p[],a,b)==)
return dis(p[]-a)<dis(p[]-b);
return mul(p[],a,b)>;
}
int Graham(int n)
{
int i,k = ,top;
point tmp;
for(i = ; i < n; i++)
{
if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
k = i;
}
if(k!=)
{
tmp = p[];
p[] = p[k];
p[k] = tmp;
}
sort(p+,p+n,cmp);
ch[] = p[];
ch[] = p[];
top = ;
for(i = ; i < n ; i++)
{
while(top>&&dcmp(mul(ch[top-],ch[top],p[i]))<)
top--;
top++;
ch[top] = p[i];
}
return top;
}
int dot_online_in(point p,point l1,point l2)
{
return !dcmp(mul(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
}
int main()
{
int n,m,i;
cin>>n;
for(i = ; i < n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].flag = ;
}
cin>>m;
for(i = n ; i < n+m; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].flag = ;
q[i-n] = p[i];
}
int tn = Graham(n+m);
ch[tn+] = ch[];
int ff = ;
for(i = ; i < m ; i++)
{
if(dot_online_in(q[i],ch[tn],ch[tn+]))
{
ff = ;
//cout<<p[i].x<<" "<<p[i].y<<endl;
break;
}
}
if(!ff)
{
puts("NO");
return ;
}
for(i = ; i <= tn ; i++)
if(ch[i].flag) {ff = ;break;}
if(ff) puts("YES");
else puts("NO");
return ;
}
CodeForces 166B (凸包)的更多相关文章
- Codeforces 166B - Polygon (判断凸包位置关系)
Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...
- CodeForces - 605C 凸包+直线与凸包判交
题目大意: 要完成两种属性p,q的需求,给定n个双属性物品及其单位个物品中含有的属性,要求选择最少的物品来达成属性需求.(可以选择实数个物品) 题解: 实际上是一种属性混合问题 我们知道对于两种双属性 ...
- Codeforces 1137E 凸包
题意:有一辆火车,初始只有一个车厢,权值为0.有3种操作: 1:在火车头前面加若干辆车 2:在火车车尾加若干辆车 3:每个车的权值加上b + (i - 1) * s,其中i是指这节车厢是从头算的第几个 ...
- codeforces 70D Professor's task(动态二维凸包)
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...
- [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)
题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...
- codeforces 70 D. Professor's task 动态凸包
地址:http://codeforces.com/problemset/problem/70/D 题目: D. Professor's task time limit per test 1 secon ...
- [codeforces/gym/101350/L]维护“凸包”
题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...
- Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)
https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...
随机推荐
- Thinking in Java——笔记(6)
Access Control A piece of work isn't good until it's been rewritten, often many times. Thus a primar ...
- Ignoring Extra Elements in mongoDB C# Driver
MongoDB删除字段后会报错: Element ... does not match any field or property of class Customer. 需要在实体类增加 [BsonI ...
- 一个ICMP单元
unit ICMPUtils; interface {$IFDEF VER80} { This source file is *NOT* compatible with Delphi 1 becaus ...
- python file模块 替换输入内容脚本
root@python-10:/home/liujianzuo/python/test# ls passwd rc.local test1 root@python-10:/home/liujianzu ...
- WWDC 2013 Session笔记 - iOS7中的多任务
这是我的WWDC2013系列笔记中的一篇,完整的笔记列表请参看这篇总览.本文仅作为个人记录使用,也欢迎在许可协议范围内转载或使用,但是还烦请保留原文链接,谢谢您的理解合作.如果您觉得本站对您能有帮助, ...
- soap和wsdl的定义
SOAP(Simple Object Access Protocol)是一个严格定义的信息交换协议,用于在Web Service中把远程调用和返回封装成机器可读的格式化数据.事实上SOAP数据使用XM ...
- SLAM数据集
数据集 New College Dataset :: Main / Downloads Autonomous Space Robotics Lab: Devon Island Rover Naviga ...
- Netty之Java堆外内存扫盲贴
Java的堆外内存本来是高贵而神秘的东西,只在一些缓存方案的收费企业版里出现.但自从用了Netty,就变成了天天打交道的事情,毕竟堆外内存能减少IO时的内存复制,不需要堆内存Buffer拷贝一份到直接 ...
- 单用户模式下连接被占用定位spid
报错The database is in single-user mode, and a user is currently connected to it. 通过 select * from sys ...
- 十六、Java基础---------集合框架之Set
写在前面的话,这篇文章在昨天就写好了,今天打开的时候一不小心将第二天的文章粘贴到了这篇文章,很不幸的是除了标题之外依然面目全非,今天带着沉痛的心情再来写这篇文章! 上篇文章介绍了Collection体 ...