题意是逆时针方向给你两个多边形,问你这两个多边形通过旋转和平移能否拼成一个凸包。

首先可以想到的便是枚举边,肯定是有一对长度相同的边贴合,那么我们就可以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(凸包)的更多相关文章

  1. POJ 2007 Scrambled Polygon 凸包

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7214   Accepted: 3445 ...

  2. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

  3. POJ 1228 Grandpa's Estate(凸包)

    Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11289   Accepted: 3117 ...

  4. [LeetCode] Convex Polygon 凸多边形

    Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...

  5. Leetcode: Convex Polygon

    Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...

  6. HOJ 13101 The Triangle Division of the Convex Polygon(数论求卡特兰数(模不为素数))

    The Triangle Division of the Convex Polygon 题意:求 n 凸多边形可以有多少种方法分解成不相交的三角形,最后值模 m. 思路:卡特兰数的例子,只是模 m 让 ...

  7. ACM训练联盟周赛 G. Teemo's convex polygon

    65536K   Teemo is very interested in convex polygon. There is a convex n-sides polygon, and Teemo co ...

  8. 【LeetCode】469. Convex Polygon 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计算向量夹角 日期 题目地址:https://leet ...

  9. POJ 2007 Scrambled Polygon 凸包点排序逆时针输出

    题意:如题 用Graham,直接就能得到逆时针的凸包,找到原点输出就行了,赤果果的水题- 代码: /* * Author: illuz <iilluzen[at]gmail.com> * ...

随机推荐

  1. zabbix 磁盘自动发现脚本

    ##需要在zabbix界面配置宏变量===>正则来匹配磁盘 disk_discovery.sh ———————————————————————————————————————————————— ...

  2. C# 更改 Hashtable key 名称

    Hashtable ht = new Hashtable(); ht[; ht["B"] = ht["标题"]; ht.Remove("标题" ...

  3. layui table 改

    F.prototype.pullData = function(e) { success: function (t) { var da001 = i; window.getdata1234567(da ...

  4. sh_04_累加求和

    sh_04_累加求和 # 计算 0 ~ 100 之间所有数字的累计求和结果 # 0. 定义最终结果的变量 result = 0 # 1. 定义一个整数的变量记录循环的次数 i = 0 # 2. 开始循 ...

  5. BOM和DOM的操作

    到目前为止,我们已经学过了JavaScript的一些简单的语法.但是这些简单的语法,并没有和浏览器有任何交互.也就是我们还不能制作一些我们经常看到的网页的一些交互,我们需要继续学习BOM和DOM相关知 ...

  6. Android中StatFs获取系统/sdcard存储(剩余空间)大小

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  7. 使用WebStorm运行vue项目

    在WebStorm中怎么打开一个已有的项目,这个不用多说,那么如何运行一个vue项目呢? 1.点击下图中右上角的红框. 2.在出现的弹框中选中左上角“+”下的“npm”,如下图所示. 3.选中第二步的 ...

  8. 学习日记21、IE下的Ajax需要注意的地方

    上面这张图片我是封装了一个easyui下拉框,红框出则是动态传入的json数据,这串代码在google下运行不会有任何问题,但是在IE下运行则会提示缺少:,这是因为IE只识别json格式的数据,所以这 ...

  9. Oracle-RAC sysdate和current_date时间不一致,导致客户端连接时间延迟

    [oracle@oracle-db1 ~]$ dateTue Oct 10 14:20:56 CST 2017[oracle@oracle-db1 ~]$ cat /etc/sysconfig/clo ...

  10. Java中String的 "引用" 传递

    1.来看一段有趣但又让人困惑的代码片段 public static void main(String[] args){ String x = new String("ab"); c ...