[BZOJ4570][数学][凸包]SCOI2016:妖怪

BZOJ4570

要求的是 m a x ( m i n ( x i + y i + a b x i + b a y i ) ) max(min(x_i+y_i+\frac{a}{b}x_i+\frac{b}{a}y_i)) max(min(xi+yi+baxi+abyi)),由对勾函数的性质得 a b = x i y i \frac{a}{b}=\sqrt{\frac{x_i}{y_i}} ba=yixi
观察一下发现就是求上凸壳,然后用边来更新一下答案

Code:

#include<bits/stdc++.h>
#define db double
using namespace std;
inline int read(){
	int res=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-f;ch=getchar();}
	while(isdigit(ch)) {res=(res<<1)+(res<<3)+(ch^48);ch=getchar();}
	return res*f;
}
const int N=1e6+5;
const db INF=sqrt(DBL_MAX);
const db eps=1e-8;
struct point{
	db x,y;
	point(){}
	point(db _x,db _y):x(_x),y(_y){}
	friend inline point operator - (const point &a,const point &b) {return point(a.x-b.x,a.y-b.y);}
	friend inline db operator *	(const point &a,const point &b){return a.x*b.y-a.y*b.x;}
}p[N],q[N];
int n,cnt=0;
inline bool cmp(const point &a,const point &b){if(a.x==b.x) return a.y<b.y;return a.x<b.x;}
inline void convex(){
	sort(p+1,p+n+1,cmp);
	for(int i=n;i>=1;i--){
		while(cnt>2 && (p[i]-q[cnt-1])*(q[cnt]-q[cnt-1])>=0) --cnt;
		q[++cnt]=p[i];
	}
	while(cnt>1 && q[cnt].y<=q[cnt-1].y) --cnt;
}
inline db slope(point a,point b){return (b.y-a.y)/(b.x-a.x);}
int main(){
	n=read();
	for(int i=1;i<=n;i++) p[i].x=read(),p[i].y=read();
	convex();
	db l=-INF,r,k;
    db ans=INF;
    for(int i=1;i<=cnt;i++){
        r=l,l=i!=cnt?slope(q[i],q[i+1]):-eps;
        k=-sqrt(q[i].y/(1.0*q[i].x));
        if(l<=k&&k<=r) ans=min(ans,q[i].x+q[i].y+q[i].x*(-k)+q[i].y/(-k));
        else ans=min(ans,q[i].x+q[i].y+q[i].x*(-l)+q[i].y/(-l)),ans=min(ans,q[i].x+q[i].y+q[i].x*(-r)+q[i].y/(-r));
    }
    printf("%.4lf",ans);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值