题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1670
单调栈维护凸包即可,用叉积判断;
维护上凸壳,然后把所有点的纵坐标翻转再求上凸壳即可,要注意排序规则略有变化。
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef double db;
int const xn=;
db const eps=1e-;
int n,top,mx;
db ans;
struct N{
db x,y;
N(db x=,db y=):x(x),y(y) {}
bool operator < (const N &b) const
{return x<b.x||(x==b.x&&y<b.y);}
}p[xn],sta[xn];
bool cmp(N a,N b){return a.x<b.x||(a.x==b.x&&a.y>b.y);}
N operator - (const N &a,const N &b){return N(a.x-b.x,a.y-b.y);}
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
int maxx(int x,int y){return x<y?y:x;}
db sqr(db x){return x*x;}
db cross(N a,N b){return a.x*b.y-a.y*b.x;}
db len(N a){return sqrt(sqr(a.x)+sqr(a.y));}
db dis(N a,N b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
int dmp(db x){if(fabs(x)<=eps)return ; return x>eps?:-;}
void work()
{
top=;
for(int i=;i<=n;i++)
{
while(top>&&dmp(cross(sta[top]-sta[top-],p[i]-sta[top]))>=)top--;
sta[++top]=p[i];
}
while(top>)ans+=len(sta[top]-sta[top-]),top--;
}
int main()
{
n=rd(); mx=;
for(int i=;i<=n;i++)p[i].x=rd(),p[i].y=rd(),mx=maxx(mx,p[i].y);
sort(p+,p+n+);
work();
for(int i=;i<=n;i++)p[i].y=mx-p[i].y+;
sort(p+,p+n+,cmp);//
work();
printf("%.2f\n",ans);
return ;
}