[Codeforces166B]Polygons 凸包
大致题意:
给你一个凸多边形A,和一个任意多边形B,判断B是否在A的内部
先对A的点集建凸包,然后枚举B中的点,二分判断是否在A的内部。
二分时可用叉积判断,详细见代码
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e6+7
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
bool operator < (const Point &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
Point operator - (const Point &a)const{
return Point(x-a.x,y-a.y);
}
Point operator + (const Point &a)const{
return Point(x+a.x,y+a.y);
}
Point operator * (const double &a)const{
return Point(x*a,y*a);
}
Point operator / (const double &a)const{
return Point(x/a,y/a);
}
void read(){
scanf("%lf%lf",&x,&y);
}
void out(){
cout<<"debug: "<<x<<" "<<y<<endl;
}
bool operator == (const Point &a)const{
return dcmp(x-a.x)== && dcmp(y-a.y)==;
}
};
double Dot(Vector a,Vector b) {
return a.x*b.x+a.y*b.y;
}
double dis(Vector a) {
return sqrt(Dot(a,a));
}
double Cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
int ConvexHull(Point *p,int n,Point *ch){
int m=;
For(i,,n-) {
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
Fore(i,n-,){
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
}
int n1,n2,m;
Point p1[],p2[];
Point ch[];
bool check(Point tp){
if(Cross(tp-ch[],ch[]-ch[])>= || Cross(tp-ch[],ch[m-]-ch[])<=) return ;
int l=,r=m-;
int now=l;
while(l<=r) {
int mid=l+r>>;
if(Cross(ch[mid]-ch[],tp-ch[])>) l=mid+,now=mid;
else r=mid-;
}
return Cross(ch[(now+)%m]-ch[now],tp-ch[now])>;
}
void solve(){
cin>>n1;
For(i,,n1-) p1[i].read();
cin>>n2;
For(i,,n2-) p2[i].read();
sort(p1,p1+n1);
m=ConvexHull(p1,n1,ch);
int mk=;
For(i,,n2-) {
if(!mk) break;
if(!check(p2[i])) mk=;
}
if(mk) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main(){
// fre("in.txt","r",stdin);
int t=;
solve();
return ;
}
[Codeforces166B]Polygons 凸包的更多相关文章
- hdu 6219 Empty Convex Polygons (凸包)
给你n个点,求面积最大的凸多边形,使得这个凸多边形没有内点. 考虑求凸包的graham算法,需要找到左下角的点,再进行极角排序后按顺序扫点,所以先枚举左下角的点. 这个过程中,如果遇到内点,就需要把这 ...
- Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包
B. Polygons time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 2017ACM/ICPC亚洲区沈阳站 C Hdu-6219 Empty Convex Polygons 计算几何 最大空凸包
题面 题意:给你一堆点,求一个最大面积的空凸包,里面没有点. 题解:红书板子,照抄完事,因为题目给的都是整点,所以最后答案一定是.5或者.0结尾,不用对答案多做处理 #include<bits/ ...
- hdu6219 Empty Convex Polygons (最大空凸包板子
https://vjudge.net/contest/324256#problem/L 题意:给一堆点,求最大空凸包面积. 思路:枚举凸包左下角点O,dp找出以这个点为起始位置能构成的最大空凸包面积, ...
- POJ 3135 Polygons on the Grid(枚举+凸包)
题目大意是让你用这n条边放在网格上构成凸包,并且边的两端点必须在网格上. 那么比较容易想到的就是枚举可能情况,因为这样的勾股数组成情况不多,因此可以直接枚举所有连出去的边反映在坐标轴上的所有情况,最后 ...
- POJ 3608 Bridge Across Islands(旋转卡壳,两凸包最短距离)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7202 Accepted: ...
- poj 3608(旋转卡壳求解两凸包之间的最短距离)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9768 Accepted: ...
- POJ 3608 凸包间最短距离(旋转卡壳)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11539 Accepted: ...
- poj 3525 求凸包的最大内切圆
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3640 ...
随机推荐
- uboot&kernel&system
- Install Terraform on Windows, Linux and Mac OS
Step-by-step tutorial of how to download and install Terraform on Windows, Linux and Mac OS. Terrafo ...
- 前端PHP入门-024-字符串函数-API查看
数组.字符串和数据库是我们函数里面最.最.最常用的三类函数,数组和数据库我们现在还没有讲到,等讲到的时候我们再来和大家细说. 当然PHP的字符串函数也有很多.我们最常使用的两个系列的字符串: 单字节字 ...
- libxml2在mingw下编译
1.配置MingW路径,在环境变量path中加入/mingw32/bin2.解压libxml,进入win32目录3.记事本打开configure.js,找到var compiler = "m ...
- 5W次单点修改,求最长的连续上升子序列 HDU 3308
题目大意:给你n个数,m个操作. 有两种操作: 1.U x y 将数组第x位变为y 2. Q x y 问数组第x位到第y位连续最长子序列的长度. 对于每次询问,输出连续最长子序列的长度 思路:用线段树 ...
- 2D旋转和3D旋转
2D旋转 先给个容器 <p onClick="rotate2D()" id="rotate2D" class="animated_div&quo ...
- 调试android chrome web page简明备忘
必备工具 adb tools.android chrome 先开启手机调试模式 adb forward tcp:9919 localabstract:chrome_devtools_remote 成功 ...
- asp.net DataTable导出 excel的方法记录(第三方)
官网:http://npoi.codeplex.com/ 简单应用,主要是可以实现我们想要的简单效果,呵呵 需要引入dll,可以在官网下载,也可在下面下载 protected void getExce ...
- Redis笔记之常用命令
keys keys用来获取符合指定规则的键,keys的语法规则如下: keys <pattern> 比如最简单的全等匹配,下面这个命令只会匹配键值完全等于foo的: 127.0.0.1:6 ...
- 爬虫实战--基于requests 和 Beautiful的7160美图网爬取图片
import requests import os from bs4 import BeautifulSoup import re # 初始地址 all_url = 'http://www.7160. ...