[Codeforces50C]Happy Farm 5 凸包
大致题意:
平面上有n个整数点,问你最少经过多少步能够将所有点严格包围。
将点严格包围要求你走的路径完全包围给出的点且不能有点在路径上
你只能走整数点,且方向只有上下左右左上右下等8个方向,每次移动一格。
答案
先对点构造凸包,答案即为每条边 max(abs(x1-x2),abs(y1-y2))的累加和+4;
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e6+7
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
bool operator < (const Point &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
Point operator - (const Point &a)const{
return Point(x-a.x,y-a.y);
}
Point operator + (const Point &a)const{
return Point(x+a.x,y+a.y);
}
Point operator * (const double &a)const{
return Point(x*a,y*a);
}
Point operator / (const double &a)const{
return Point(x/a,y/a);
}
void read(){
scanf("%lf%lf",&x,&y);
}
void out(){
cout<<"debug: "<<x<<" "<<y<<endl;
}
bool operator == (const Point &a)const{
return dcmp(x-a.x)== && dcmp(y-a.y)==;
}
};
double Dot(Vector a,Vector b) {
return a.x*b.x+a.y*b.y;
}
double dis(Vector a) {
return sqrt(Dot(a,a));
}
double Cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
int ConvexHull(Point *p,int n,Point *ch){
int m=;
For(i,,n-) {
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
Fore(i,n-,){
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
}
bool cmp(Point a,Point b){
return a.y<b.y;
}
int n,m;
Point p[];
Point ch[];
void solve(){
cin>>n;
int ans=;
For(i,,n-) p[i].read();
sort(p,p+n);
m=ConvexHull(p,n,ch);
For(i,,m-) {
Point tp=ch[(i+)%m]-ch[i];
ans+=max(abs(tp.x),abs(tp.y));
}
cout<<ans+<<endl;
}
int main(){
// fre("in.txt","r",stdin);
int t=;
solve();
return ;
}
[Codeforces50C]Happy Farm 5 凸包的更多相关文章
- 【POJ】1228 Grandpa's Estate(凸包)
http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- Beauty Contest(graham求凸包算法)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25256 Accepted: 7756 Description Bess ...
- POJ 1228 Grandpa's Estate(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- poj 1228 稳定凸包
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12337 Accepted: 3451 ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)
Building Fence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
随机推荐
- DINSTINCT
DISTINCT是对结果集进行去重,有三点需要注意. 1.在大多数情况下(两者后面所跟的字段相同时),DISTINCT跟group by是等效的,此时DISTINCT可以看作group by的一个特例 ...
- 使用$http.post()提交数据后台接收不到
传参方式是request payload,参数格式是json,而并非用的是form传参,所以在后台用接收form数据的方式接收参数就接收不到了. POST表单请求提交时,使用的Content-Type ...
- php7.1安装
找到对应的镜像,右键复制链接地址这里下载的镜像是PHP7http://cn2.php.net/get/php-7.1.0.tar.gz/from/this/mirror 最后通过wget下载这个地址里 ...
- Ajax笔记-加强版
AJAX : Asynchronous JavaScript and XML 异步JavaScript和XML 用javascript异步形式去操作xml 进行数据交互 节省用户操作,时间 ...
- 「LibreOJ β Round #4」多项式 (广义欧拉数论定理)
https://loj.ac/problem/525 题目描述 给定一个正整数 kkk,你需要寻找一个系数均为 0 到 k−1之间的非零多项式 f(x),满足对于任意整数 x 均有 f(x)modk= ...
- NOIP2013 提高组 Day1
https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83%7C30 期望得分:100+100+100=300 实际得 ...
- Codeforces 807 A Is it rated?
http://codeforces.com/problemset/problem/807/A A. Is it rated? time limit per test 2 se ...
- Spring Cloud全家桶主要组件及简要介绍
一.微服务简介 微服务是最近的一两年的时间里是很火的一个概念.感觉不学习一下都快跟不上时代的步伐了,下边做一下简单的总结和介绍. 何为微服务?简而言之,微服务架构风格这种开发方法,是以开发一组小型服务 ...
- 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)
题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...
- http://www.onvif.org/onvif/ver20/util/operationIndex.html
http://www.onvif.org/onvif/ver20/util/operationIndex.html