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 ...
随机推荐
- Android RecyclerView的基本使用
Android RecyclerView 在去年的Google I/O大会上就推出来了,以前经常使用的ListView 继承的是AbsListView,而RecyclerView则直接继承 ViewG ...
- pageX、pageY全兼容
pageX.pageY全兼容 var pos=function(o,x,y,event){var posX=0,posY=0;var e=event||window.event;if(e.posX|| ...
- java中日历代码的实现
import java.util.Scanner; com.lv.calendarWatch//包名 /* * 需求:输入一个年份和月份 ,显示当前月日情况 ,星期数要对应准确 * 1.1900年1月 ...
- php +html5 websocket 聊天室
针对内容比较长出错,修改后的解码函数 和 加码函数 原文请看上一篇 http://yixun.yxsss.com/yw3104.html function uncode($str,$key){ $ma ...
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
开启tomcat时出现以上错误 // 进入root帐户 在普通用户也可以 sudo -s //用编辑器打开.bashrc文件 gedit .bashrc 在普通用户下注意加上sudo //在最后一行添 ...
- apache php env build
from http://blog.csdn.net/yincg/article/details/8782364 1.1 系统说明Centos 6.2 (最小化安装)1.2 软件说明httpd-2.4. ...
- socket.io稳定性及事件测试
socket.io测试报告 1.socekt.io能坚持多久 将服务器上的socekt.io代码从早上9:30分开始运行到晚上18点,每100毫秒发送一条数据,数据大概15个字符,同时开启5个连接 结 ...
- Oracle常用日期函数
常用的时间格式掩码如下:掩码元素 含义YYYY 四位数年份 (如:2005) yearYY 二位数年份(如 05) Q ...
- Android 程序崩溃后的处理
在应用发布以后,由于安卓机型的千差万别 ,可能会出现各种各样的问题,这时候如果我们可以将这些信息收集起来,并进行修改就很不错了.下面就来讨论一下怎么处理程序崩溃以后,错误信息的手机. Java中已经提 ...
- JS逗号运算符的用法详解
逗号运算符的用法详解 注意: 一.由于目前正在功读JavaScript技术,所以这里拿JavaScript为例.你可以自己在PHP中试试. 二.JavaScript语法比较复杂,因此拿JavaScri ...