【凸包板题】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 ...
随机推荐
- JS 判断object是否包含某个键
1. myObj.hasOwnProperty('myKey'); 2. if ('key' in myObj)
- Cannot attach the file as database
Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sqlloca ...
- C#sql语句
SQL语句大全删除数据库 drop database databasename SQL语句大全备份 --- 创建备份数据的 device USE master EXEC sp_addumpdevice ...
- 5. BERT算法原理解析
1. 语言模型 2. Attention Is All You Need(Transformer)算法原理解析 3. ELMo算法原理解析 4. OpenAI GPT算法原理解析 5. BERT算法原 ...
- Linux查看文件总的数据行数,并按行拆分
先利用 wc -l BLM.txt 读出 BLM.txt 文件一共有多少行. 再 1. 以行数拆分 -l 参数: split –l 50 原始文件 拆分后文件名前缀 例:以50行对文件进行 ...
- stm32之TIM+ADC+DMA采集50HZ交流信号
http://cache.baiducontent.com/c?m=9d78d513d98207f04fece47f0d01d7174a02d1743ca6c76409c3e03984145b5637 ...
- [sso]搭建CAS单点服务器
1.下载服务器端文件 Cas Client下载:http://developer.jasig.org/cas-clients/ CAS Server:cas-server-4.0.0-release. ...
- [Installing Metasploit Framework on CentOS_RHEL 6]在CentOS_RHEL 6上安装Metasploit的框架【翻译】
[Installing Metasploit Framework on CentOS_RHEL 6]在CentOS_RHEL 6上安装Metasploit的框架[翻译] 标记声明:蓝色汉子为翻译上段英 ...
- PI SQL 语句
insert [piarchive]..[picomp2](tag,time,value) values('ppnie_test','t',100) INSERT into pipoint..clas ...
- 《精通Python网络爬虫》
抓包工具 Fiddler 爬虫的浏览器伪装技术 Python Scrapy 框架