POJ 3410 Split convex polygon(凸包)
题意是逆时针方向给你两个多边形,问你这两个多边形通过旋转和平移能否拼成一个凸包。
首先可以想到的便是枚举边,肯定是有一对长度相同的边贴合,那么我们就可以n2枚举所有边对,接下来就是旋转点对,那么假设多边型在这条向量的左侧,那么我们可以根据叉积正负判断旋转的方向。
然后就是如何判断了,显然有一种情况是凸包里扣除整个多边形,那么这种情况我们需要对重合的边进行删除,可以发现,如果有重合的边,他一定是成对出现,有一条进去的边也有一条出来的边,那么我们可以直接通过vector不断插入的过程和之前那条边比较,是否是同一对点产生的边,如果是我们就直接抵消,进行下一次判断。
最后就是对这些绕着一圈的点进行判断是否是凸包,那么我们直接绕一圈判断两个向量叉积是否是小于0或者叉积等于0但是方向相反,那么这种情况也是非法。
还是有很多细节地方,此题好像eps要开大一点,不然会wa。


ans= ans=
// ——By DD_BOND //#include<bits/stdc++.h>
//#include<unordered_map>
//#include<unordered_set>
#include<functional>
#include<algorithm>
#include<iostream>
//#include<ext/rope>
#include<iomanip>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cstddef>
#include<cstdio>
#include<memory>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
#include<queue>
#include<deque>
#include<ctime>
#include<stack>
#include<map>
#include<set> #define fi first
#define se second
#define pb push_back
#define MP make_pair using namespace std; typedef double db;
typedef long ll;
typedef pair<db,db> Pd;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll; const db eps=1e-;
const int MAXN=1e3+;
const db pi=acos(-1.0);
const ll INF=0x3f3f3f3f3f3f3f3f; inline int dcmp(db x){
if(fabs(x)<eps) return ;
return (x>? : -);
} inline db Sqrt(db x){
return x>? sqrt(x): ;
} inline db sqr(db x){ return x*x; } struct Point{
db x,y;
Point(){ x=,y=; }
Point(db _x,db _y):x(_x),y(_y){}
void input(){
double _x,_y;
scanf("%lf%lf",&_x,&_y);
x=_x,y=_y;
}
bool operator ==(const Point &b)const{
return (dcmp(x-b.x)==&&dcmp(y-b.y)==);
}
bool operator <(const Point &b)const{
return (dcmp(x-b.x)==? dcmp(y-b.y)< : x<b.x);
}
Point operator +(const Point &b)const{
return Point(x+b.x,y+b.y);
}
Point operator -(const Point &b)const{
return Point(x-b.x,y-b.y);
}
Point operator *(db a){
return Point(x*a,y*a);
}
Point operator /(db a){
return Point(x/a,y/a);
}
db len2(){ //长度平方
return sqr(x)+sqr(y);
}
db len(){ //长度
return Sqrt(len2());
}
db polar(){ //向量的极角
return atan2(y,x); //返回与x轴正向夹角(-pi~pi]
}
Point change_len(db r){ //转化为长度为r的向量
db l=len();
if(dcmp(l)==) return *this; //零向量
return Point(x*r/l,y*r/l);
}
Point rotate(Point p,db ang){ //绕点p逆时针旋转ang度
Point v=(*this)-p;
db c=cos(ang),s=sin(ang);
return Point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
}
}; inline db cross(Point a,Point b){ //叉积
return a.x*b.y-a.y*b.x;
} inline db dot(Point a,Point b){ //点积
return a.x*b.x+a.y*b.y;
} inline db dis(Point a,Point b){ //两点的距离
Point p=b-a; return p.len();
} db rad(Point a,Point b){ //两个向量的夹角
return fabs(atan2(fabs(cross(a,b)),dot(a,b)));
} struct Node{
Point vec,s,t;
Node(){}
Node(Point a,Point b,Point c){
vec=a,s=b,t=c;
}
}; Point a[],b[],tmp[]; int main(void){
int n;
while(~scanf("%d",&n)){
int ans=;
for(int i=;i<n;i++) a[i].input(),a[i+n]=a[i];
int m; scanf("%d",&m);
for(int i=;i<m;i++) b[i].input(),b[i+m]=b[i]; for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(dcmp(dis(a[i],a[i+])-dis(b[j],b[j+]))==){
int p=,f=;
vector<Node>st;
db ang=rad(b[j+]-b[j],a[i+]-a[i]);
if(dcmp(cross(b[j+]-b[j],a[i+]-a[i]))>=) ang-=pi;
else ang=pi-ang; for(int k=;k<i;k++) tmp[p++]=a[k];
for(int k=j+;k<j+m+;k++) tmp[p++]=a[i+]+(b[k]-b[j]).rotate(Point(,),ang);
for(int k=i+;k<n;k++) tmp[p++]=a[k]; tmp[p]=tmp[]; for(int i=;i<p;i++){
Point res=tmp[i+]-tmp[i];
if(st.size()&&st.back().t==tmp[i]&&st.back().s==tmp[i+]) st.pop_back();
else st.pb(Node(res,tmp[i],tmp[i+]));
} st.pb(st[]);
for(int i=;i<(int)st.size();i++)
if(dcmp(cross(st[i-].vec,st[i].vec))<||
(dcmp(cross(st[i-].vec,st[i].vec))==&&dcmp(dot(st[i-].vec,st[i].vec))<=))
f=;
if(!f) ans=;
}
printf("%d\n",ans);
}
return ;
}
POJ 3410 Split convex polygon(凸包)的更多相关文章
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- POJ 1228 Grandpa's Estate(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- [LeetCode] Convex Polygon 凸多边形
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- Leetcode: Convex Polygon
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- HOJ 13101 The Triangle Division of the Convex Polygon(数论求卡特兰数(模不为素数))
The Triangle Division of the Convex Polygon 题意:求 n 凸多边形可以有多少种方法分解成不相交的三角形,最后值模 m. 思路:卡特兰数的例子,只是模 m 让 ...
- ACM训练联盟周赛 G. Teemo's convex polygon
65536K Teemo is very interested in convex polygon. There is a convex n-sides polygon, and Teemo co ...
- 【LeetCode】469. Convex Polygon 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计算向量夹角 日期 题目地址:https://leet ...
- POJ 2007 Scrambled Polygon 凸包点排序逆时针输出
题意:如题 用Graham,直接就能得到逆时针的凸包,找到原点输出就行了,赤果果的水题- 代码: /* * Author: illuz <iilluzen[at]gmail.com> * ...
随机推荐
- npm 和 cnpm 区别
来源:https ://blog.csdn.net/shelly1072/article/details/51524029 NPM介绍: 说明:NPM(节点包管理器)是的NodeJS的包管理器,用于节 ...
- Cassandra介绍
Cassandra介绍 Apache Cassandra 是一个开源的.分布式.无中心.弹性可扩展.高可用.容错.一致性可调.面向列的数据库.它基于Amazon Dynamo的分布式设计 Cassan ...
- datatable 和实体互转
public static class ModelConvertHelper<T> where T : class,new() { public static List<T> ...
- C# 泛型 new{ }??? //加new 和不加new 有什么不同? new() 约束
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- vue学习-day03(动画,组件)
目录: 1.品牌列表-从数据库获取列表 2.品牌列表-完成添加功能 3.品牌列表-完成删除功能 4.品牌列表-全局配置数据接口的根域名 5.品牌列表-全局配置emulateJS ...
- 病毒 x
04:病毒 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65535kB 描述 有一天,小y突然发现自己的计算机感染了一种病毒!还好,小y发现这种病毒很弱,只是会把文档中的所有字 ...
- sh_10_体验模块
sh_10_体验模块 import sh_10_分隔线模块 sh_10_分隔线模块.print_line("-", 50) print(sh_10_分隔线模块.name)
- 新手 Redis 配置笔记(windows),附下载地址
1.关于安装文件的选择 安装的时候应该下载免安装版,安装版虽然一路下一步就可以了,但是,当要修改配置文件的时候,特别痛苦,搜了两个小时,居然没有找到如何用命令修改配置文件,开放远程连接.所以对于第一次 ...
- Selenium 多窗口切换
我们在操作网页的时候,点击有些页面的链接,会重新打开一个窗口,我们要在新页面上操作,就得切换窗口 比如在百度首页的登录框点击注册,会重新打开一个注册的新页面,要在新页面注册,就得先切进新页面 那我们怎 ...
- ZooKeeper 原生API操作
zookeeper客户端和服务器会话的建立是一个异步的过程,也就是说在程序中,程序方法在处理完客户端初始化后立即返回(即程序继续往下执行代码,这样,在大多数情况下并没有真正的构建好一个可用会话,在会话 ...