【凸包板题】Gym - 101484E E. Double Fence
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的更多相关文章
- hdu 1348 Wall(凸包模板题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) M ...
- BZOJ 4522: [Cqoi2016]密钥破解 (Pollard-Rho板题)
Pollard-Rho 模板 板题-没啥说的- 求逆元出来后如果是负的记得加回正数 CODE #include<bits/stdc++.h> using namespace std; ty ...
- Oil Skimming HDU - 4185(匹配板题)
Oil Skimming Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- Luogu P3690【模板】Link Cut Tree (LCT板题)
省选前刷道LCT板题(话说之前没做这道题-) CODE #include<bits/stdc++.h> using namespace std; inline void read(int ...
- BZOJ 1180 [CROATIAN 2009]OTOCI // BZOJ 2843 极地旅行社 // Luogu P4321 [COCI 2009] OTOCI / 极地旅行社 (LCA板题)
emmm-标题卡着长度上限- LCT板题-(ε=ε=ε=┏(゜ロ゜;)┛) CODE #include <cctype> #include <cmath> #include & ...
- [GYM 100492A] Average Convex Hull 凸包好题
大致题意: 给出一个点集,其中有一个点有相同的几率会被删除,求删除之后的点集够成的凸包上的点的平均数. 首先看到题目,可以考虑枚举删除的点,将其凸包上前后两点以及两点间凸包内所有点构建凸包,因为凸包内 ...
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- UVA 11800 Determine the Shape --凸包第一题
题意: 给四个点,判断四边形的形状.可能是正方形,矩形,菱形,平行四边形,梯形或普通四边形. 解法: 开始还在纠结怎么将四个点按序排好,如果直接处理的话,有点麻烦,原来凸包就可搞,直接求个凸包,然后点 ...
- POJ 1113 凸包模板题
上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorit ...
随机推荐
- MySQL -- Innodb中的change buffer
change buffer是一种特殊的数据结构,当要修改的辅助索引页不在buffer pool中时,用来cache对辅助索引页的修改.对辅助索引页的操作可能是insert.update和delete操 ...
- 9.5 翻译系列:数据注解之ForeignKey特性【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code ...
- Java 8 – MinguoDate examples
1. LocalDate -> MinguoDate Review a full example to convert a LocalDate to MinguoDate TestMinguoD ...
- Android开发(二十三)——Application
参考: [1] Android中Application类用法.http://www.cnblogs.com/renqingping/archive/2012/10/24/Application.htm ...
- select理解
https://www.cnblogs.com/skyfsm/p/7079458.html
- Ubuntu和centos离线安装软件包(apt和yum)
linux安装软件包要解决包依赖问题,不能简单安装包本身. 离线安装基本思想都是先在一台设备上安装下载所有依赖包,然后拷贝所有依赖包到新设备上安装. Ubuntu下apt离线安装包 执行apt upd ...
- Spring Mvc 入门Demo
1.web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns=" ...
- GitHub私有代码库将免费开放
1月8号消息,微软收购 GitHub 后,官方宣布了一项重大更新:免费开放私有代码库, 即 GitHub 用户现在可以免费创建无限量的私有存储库.同时还有另一项更新——GitHub Enterpris ...
- java 汉诺塔实现自动演示
1.增加计时功能,显示用户完成移动盘子所花费的时间 2.用户可以设置最大和最小盘子的大小 3.用户可以选择播放和暂停背景音乐 4.用户可以设置盘子的数目 5.用户可以设置盘子的颜色以及背景的颜色 6. ...
- [Python] 03 - Lists, Dictionaries, Tuples, Set
Lists 列表 一.基础知识 定义 >>> sList = list("hello") >>> sList ['h', 'e', 'l', ' ...