求一个多边形是否完全在另一个凸多边形内。

乍一看,好像要判点在多边形内,但复杂度不允许,仔细一想,可以把两个多边形的点混起来求一个共同的凸包,如果共同的凸包依旧是原来凸包上的点,说明是。

 #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 (凸包)的更多相关文章

  1. Codeforces 166B - Polygon (判断凸包位置关系)

    Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...

  2. CodeForces - 605C 凸包+直线与凸包判交

    题目大意: 要完成两种属性p,q的需求,给定n个双属性物品及其单位个物品中含有的属性,要求选择最少的物品来达成属性需求.(可以选择实数个物品) 题解: 实际上是一种属性混合问题 我们知道对于两种双属性 ...

  3. Codeforces 1137E 凸包

    题意:有一辆火车,初始只有一个车厢,权值为0.有3种操作: 1:在火车头前面加若干辆车 2:在火车车尾加若干辆车 3:每个车的权值加上b + (i - 1) * s,其中i是指这节车厢是从头算的第几个 ...

  4. codeforces 70D Professor's task(动态二维凸包)

    题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...

  5. [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)

    题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...

  6. codeforces 70 D. Professor's task 动态凸包

    地址:http://codeforces.com/problemset/problem/70/D 题目: D. Professor's task time limit per test 1 secon ...

  7. [codeforces/gym/101350/L]维护“凸包”

    题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...

  8. Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)

    https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...

  9. Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积

    Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...

随机推荐

  1. Codevs 1299 切水果

    题目链接 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 简单的说,一共N个水果排成一排,切M次,每次切[L,R]区间的所有水果 ...

  2. JS-011-颜色进制转换(RGB转16进制;16进制转RGB)

    在网页开发的时候,经常需要进行颜色设置,因而经常需要遇到进行颜色进制转换的问题,例如:RGB转16进制:16进制转RGB),前几天在测试的时候,发现网站的颜色进制转换某类16进制颜色(例如:#0000 ...

  3. 大商创 sql追踪 用户注册

    用户注册sql追踪 用户注册数据表 sql语句分析 ', 'wzd222@qq.com', 'addf92072794a4b668f70815672ba5c8') 主要成分: user_name,mo ...

  4. Android应用程序窗口(Activity)与WindowManagerService服务的连接过程分析

    在前两文中,我们分析了Activity组件的窗口对象和视图对象的创建过程.Activity组件在其窗口对象和视图对象创建完成之后,就会请求与WindowManagerService建立一个连接,即请求 ...

  5. react input 获取/失去焦点

    <div className={ this.state.focus ? "dis_bottom_left_onfocus" : "dis_bottom_left&q ...

  6. Java Servlet(四):Servlet接口service工作(ServletRequest,ServletResponse对象)(jdk7+tomcat7+eclipse)

    本篇将会记录,Servlet接收客户端传递来的参数信息,并返回信息使用的对象,及这些对象的函数相关用法. 还是在java ee工程中进行操作,在WebContent目录下创建一个login.jsp文件 ...

  7. Python 模块,数据类型,元组

    模块 Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相应的Python库支持,以后的课程中会深入讲解常用到的各种库,现在,我们先来象征性的学2个简单的. s ...

  8. mssql手工注入及绕过术

      报错注入: - 例子:http://www.kfgtfcj.xxx.cn/lzygg/Zixun_show.aspx?id=1 [1]首先爆版本:http://www.kfgtfcj.xxx.cn ...

  9. CSS 在IE6, IE7 和IE8中的差别////////////////z

    CSS 在IE6, IE7 和IE8中的差别 关于浏览器的最离奇的统计结果之一就是Internet Explorer 版本6,7和8共存.截至本文,Internet Explorer各个版本总共占据了 ...

  10. ligerui_ligerTree_005_动态增加“树”节点

    动态添加ligerTree节点:效果图: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 <%@ page language= ...