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> * ...
随机推荐
- python 面向对象_1
self #self 是相当于c++的 this指针 class Ball: def setName(self,name): self.name = name def kick(self): prin ...
- antd不可选择时间
//不能选择今天之前的日期<DatePicker format={this.timeFormat} showTime placeholder="项目结束日期" disable ...
- mysql MAX()函数 语法
mysql MAX()函数 语法 作用:返回一列中的最大值.NULL 值不包括在计算中.直线电机模组--BZD80N 语法:SELECT MAX(column_name) FROM table_nam ...
- 虚拟机使用桥接模式连接网络并且设置静态ip
1.桥接模式连接网络 虚拟机连接网络一共有四种模式,我这里只介绍桥接模式,毕竟坑了我几个小时 设置有线连接,我本来用的无线连接完成微信点餐系统,后来换了有线因为有线连接不会分配ip,和本地电脑使用同一 ...
- luogu P1314 聪明的质监员 x
P1314 聪明的质监员(至于为什么选择这个题目,可能是我觉得比较好玩呗) 题目描述 小T 是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有 n 个矿石,从 1到n 逐一编号,每个矿石都有自 ...
- Linux简介安装、系统启动过程、目录结构
Linux简介安装.系统启动过程.目录结构 Linux 教程 Linux 英文解释为 Linux is not Unix. Linux 简介 Linux内核最初只是由芬兰人李纳斯·托瓦兹(Linus ...
- python实现RGB转换HSV
def rgb2hsv(r, g, b): r, g, b = r/255.0, g/255.0, b/255.0 mx = max(r, g, b) mn = min(r, ...
- JedisCluster和springboot整合
maven依赖 springboot整合jedisCluster相当简单,maven依赖如下: <dependency> <groupId>org.springframewor ...
- nbu还原集群数据库异常问题
集群数据库软件均已安装完毕,现在想从NBU上还原数据库,但在还原控制文件报错 [oracle@oracle-db1 ~]$ rman target / Recovery Manager: Releas ...
- 3、Shiro授权
Shiro授权过程和认证过程相似: 项目结构: package com.shiro.shiroframe; import org.apache.shiro.SecurityUtils; import ...