http://codeforces.com/gym/101484/problem/E

题解 凸包板题

#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a)) const int maxn = 2e5 + ;
int a[maxn];
typedef long long ll;
const double eps = 1e-;//eps用于控制精度
struct Point//点或向量
{
double x, y;
Point() {}
Point(double x, double y) :x(x), y(y) {}
};
bool cmp1(Point a,Point b){
if(a.x==b.x)return a.y<b.y;
else return a.x<b.x;
}
struct triVec {
double x, y,z;
triVec() {}
triVec(double x, double y,double z) :x(x), y(y),z(z) {}
};
typedef Point Vector;
Vector operator + (Vector a, Vector b)//向量加法
{
return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Vector a, Vector b)//向量减法
{
return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector a, double p)//向量数乘
{
return Vector(a.x*p, a.y*p);
}
Vector operator / (Vector a, double p)//向量数除
{
return Vector(a.x / p, a.y / p);
}
int dcmp(double x)//精度三态函数(>0,<0,=0)
{
if (fabs(x) < eps)return ;
else if (x > )return ;
return -;
}
bool operator == (const Point &a, const Point &b)//向量相等
{
return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
}
double Dot(Vector a, Vector b)//内积
{
return a.x*b.x + a.y*b.y;
}
double Length(Vector a)//模
{
return sqrt(Dot(a, a));
}
Vector Rotate(Vector a, double rad)//逆时针旋转
{
return Vector(a.x*cos(rad) - a.y*sin(rad), a.x*sin(rad) + a.y*cos(rad));
}
double Cross(Vector a, Vector b)//外积
{
return a.x*b.y - a.y*b.x;
}
double Distance(Point a, Point b)//两点间距离
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
int n, m;
double z;
//Point p[maxn]; Point f1[maxn];
Point f2[maxn];
Point result[maxn];
vector<Point> P;
int top;
bool cmp(Point A, Point B)
{
double ans = Cross(A - P[], B - P[]);
if (dcmp(ans) == )
return dcmp(Distance(P[], A) - Distance(P[], B)) < ;
else
return ans > ;
}
void Graham()//Graham凸包扫描算法
{
for (int i = ; i < P.size(); i++)//寻找起点
if (P[i].y < P[].y || (dcmp(P[i].y - P[].y) == && P[i].x < P[].x))
swap(P[i], P[]);
sort(P.begin()+, P.end(), cmp);//极角排序,中心为起点
result[] = P[];
result[] = P[];
top = ;
for (int i = ; i < P.size(); i++)
{
while (Cross(result[top] - result[top - ], P[i] - result[top - ]) < && top >= )
top--;
result[++top] = P[i];
}
} int main() {
int n,m;
cin>>n>>m;
rep(i,,n){scanf("%lf%lf",&f1[i].x,&f1[i].y);P.push_back(f1[i]);}
rep(i,,m){scanf("%lf%lf",&f2[i].x,&f2[i].y);P.push_back(f2[i]);}
//if(n<=2||m<=2) return 0*printf("NO\n");
Graham();
sort(result,result+top,cmp);
sort(f1+,f1+n+,cmp);
sort(f2+,f2+n+,cmp);
int f=,ff=;
rep(i,,n){
if(!(f1[i]==result[i-]))f=; }
if(n!=top+)f=;
rep(i,,m){
if(!(f2[i]==result[i-]))ff=;
}
if(m!=top+)f=;
/* rep(i,1,n)cout<<f1[i].x<<'*'<<f1[i].y<<' ';
cout<<endl;
rep(i,1,m)cout<<f2[i].x<<'*'<<f2[i].y<<' ';
cout<<endl;
rep(i,0,top)cout<<result[i].x<<'*'<<result[i].y<<' ';
cout<<endl;*/
if(f|ff)puts("YES");
else puts("NO"); }

【凸包板题】Gym - 101484E E. Double Fence的更多相关文章

  1. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. BZOJ 4522: [Cqoi2016]密钥破解 (Pollard-Rho板题)

    Pollard-Rho 模板 板题-没啥说的- 求逆元出来后如果是负的记得加回正数 CODE #include<bits/stdc++.h> using namespace std; ty ...

  3. Oil Skimming HDU - 4185(匹配板题)

    Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. Luogu P3690【模板】Link Cut Tree (LCT板题)

    省选前刷道LCT板题(话说之前没做这道题-) CODE #include<bits/stdc++.h> using namespace std; inline void read(int ...

  5. BZOJ 1180 [CROATIAN 2009]OTOCI // BZOJ 2843 极地旅行社 // Luogu P4321 [COCI 2009] OTOCI / 极地旅行社 (LCA板题)

    emmm-标题卡着长度上限- LCT板题-(ε=ε=ε=┏(゜ロ゜;)┛) CODE #include <cctype> #include <cmath> #include & ...

  6. [GYM 100492A] Average Convex Hull 凸包好题

    大致题意: 给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数. 首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内 ...

  7. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  8. UVA 11800 Determine the Shape --凸包第一题

    题意: 给四个点,判断四边形的形状.可能是正方形,矩形,菱形,平行四边形,梯形或普通四边形. 解法: 开始还在纠结怎么将四个点按序排好,如果直接处理的话,有点麻烦,原来凸包就可搞,直接求个凸包,然后点 ...

  9. POJ 1113 凸包模板题

    上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorit ...

随机推荐

  1. 【Visual Studio】VS发布应用未能创建默认证书的问题解决方法

    解决方法:点击你创建的项目 右键> 属性>签名>从存储区选择>选择证书这时候显示无可用证书 ,然后我从文件区选择了一个结果,又出现了第二个问题.提示我“签名时出错: 指定了无效 ...

  2. primary库新增数据文件后,standby库无法创建文件并终止数据同步

    主库是RAC环境,使用asm存放数据文件,备库是操作系统本地文件系统存放数据文件.在主库执行以下操作: SQL> alter tablespace ysdv add datafile '+dat ...

  3. HDU 3277 Marriage Match III(并查集+二分答案+最大流SAP)拆点,经典

    Marriage Match III Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. CentOS7中systemctl的使用与CentOS6中service的区别

    https://blog.csdn.net/u012834750/article/details/80501440 从CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon ...

  5. git 创建标签

    在Git中打标签非常简单,首先,切换到需要打标签的分支上: $ git branch * dev master $ git checkout master Switched to branch 'ma ...

  6. TestNG源代码分析:依赖管理的实现

    TestNG源代码分析:依赖管理的实现 2018-03-19 1 背景 当case之间有依赖关系,有依赖关系的case,它们的执行顺序是有限制的.TestNG提供了依赖管理功能 2 基础理论 这个执行 ...

  7. 【iCore1S 双核心板_FPGA】例程二:GPIO输入实验——识别按键输入

    实验现象: iCore1s 双核心板上与FPGA相连的三色LED(PCB上标示为FPGA·LED),按键按下红灯点亮,松开按键红灯熄灭. 核心源代码: module KEY( input CLK_12 ...

  8. windows server r2 安装vs2017 更新补丁Windows8.1-KB2919355-x6

    方法一: 点击vs2017安装包后提示需要更新Windows8.1-KB2919355-x64补丁 点击链接进入全部下载后查看官方安装顺序为 注意 必须按照以下顺序安装更新:clearcompress ...

  9. /proc详解

    内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它常见的文件系统不同的是,/proc是一种伪文件 ...

  10. 汽车行业与 Telematics

    Telematics Telematics是远距离通信的电信(Telecommunications)与信息科学(Informatics)的合成词,按字面可定义为通过内置在汽车.航空.船舶.火车等运输工 ...