大致题意:

  平面上有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+7;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
    if(fabs(x)<=eps) return 0;
    return x<0?-1:1;
}
struct Point{
    double x,y;
    Point(double x=0,double y=0):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)==0 && dcmp(y-a.y)==0;
    }
};
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=0;
    For(i,0,n-1) {
        while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    int k=m;
    Fore(i,n-2,0){
        while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++]=p[i];
    }
    if(n>1) m--;
    return m;
}
bool cmp(Point a,Point b){
    return a.y<b.y;
}
int n,m;
Point p[100005];
Point ch[100005];
void solve(){
    cin>>n;
    int ans=0;
    For(i,0,n-1) p[i].read();
    sort(p,p+n);
    m=ConvexHull(p,n,ch);
    For(i,0,m-1) {
        Point tp=ch[(i+1)%m]-ch[i];
        ans+=max(abs(tp.x),abs(tp.y));
    }
    cout<<ans+4<<endl;
}
int main(){
//    fre("in.txt","r",stdin);
    int t=0;
    solve();
    return 0;
}
View Code