传送门

首先可以把每个妖怪看成二维平面上的一个点,那么每一个环境\((a,b)\)就可以看成一条斜率\(k=-\frac{b}{a}\)的过该点的直线,战斗力就是这条直线在两坐标轴上的截距之和

对于每一个妖怪来说,它的战斗力为\(x+y-kx-\frac{y}{k}\),后面是个对勾函数,当\(k=-\sqrt{\frac{y}{x}}\)的时候函数取到最小值

那么我们维护一个右上凸壳,然后对于每一个点先用它和上一个点的直线更新答案,然后计算它的最优斜率,如果这个斜率的直线在凸包上刚好切到这一个点那么就更新答案

复杂度\(O(nlogn)\)

我怎么感觉以前好像做过这题

//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=1e6+5;const double eps=1e-10;
inline double abs(R double x){return x<-eps?-x:x;}
inline int sgn(R double x){return x<-eps?-1:x>eps;}
struct node{
int x,y;
inline node(){}
inline node(R int xx,R int yy):x(xx),y(yy){}
inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
inline ll operator *(const node &b)const{return 1ll*x*b.y-1ll*y*b.x;}
inline bool operator <(const node &b)const{return x==b.x?y>b.y:x<b.x;}
inline double K(){return -sqrt(1.0*y/x);}
friend double sl(const node &a,const node &b){return (0.0+b.y-a.y)/(b.x-a.x);}
inline double calc(R double k){return !sgn(k)?1e18:x+y-k*x-y/k;}
}p[N],st[N];
int n,top;double ans=1e18,k,sp[N];
int main(){
// freopen("testdata.in","r",stdin);
n=read();
fp(i,1,n)p[i].x=read(),p[i].y=read();
sort(p+1,p+1+n);
st[++top]=p[1];
fp(i,2,n){
while(top>1&&(p[i]-st[top-1])*(st[top]-st[top-1])<0)--top;
st[++top]=p[i];
}
fp(i,1,top-1)sp[i]=sl(st[i],st[i+1]);sp[top]=-1e18;
fp(i,2,top){
k=st[i].K();
if(sgn(sp[i-1]-k)>=0&&sgn(k-sp[i])>=0)cmin(ans,st[i].calc(k));
cmin(ans,st[i].calc(sp[i-1]));
}
k=st[1].K();
if(sgn(k-sp[1])>=0)cmin(ans,st[1].calc(k));
printf("%.4lf\n",ans);
return 0;
}

最新文章

  1. [LeetCode] Isomorphic Strings 同构字符串
  2. MYSQL 5.7 无法启动(Could not open error log file errno 2)
  3. BI领导驾驶舱的功能特点
  4. php+js实现分页
  5. 内网机(无网络安装 .NET Core win开发环境
  6. C++ Split string into vector&lt;string&gt; by space
  7. OREACLE 数据库建表 添加判断表是否存在 不存在则新建
  8. Jetty:配置概览-须要配置什么
  9. redis源码笔记(一) —— 从redis的启动到command的分发
  10. 再起航,我的学习笔记之JavaScript设计模式21(命令模式)
  11. 使用Multiplayer Networking做一个简单的多人游戏例子-1/3(Unity3D开发之二十五)
  12. [Swift]LeetCode566. 重塑矩阵 | Reshape the Matrix
  13. Java集合中List,Set以及Map等集合体系详解(史上最全)
  14. JavaSE| 数组
  15. MySQL命令学习
  16. js十大排序算法:冒泡排序
  17. 使用GPStracker自建卫星定位跟踪平台
  18. Vue SSR配合Java的Javascript引擎j2v8实现服务端渲染1概述
  19. 河南省第七届ACM程序设计大赛总结
  20. HttpServletRequest继承字ServletRequest的常用方法

热门文章

  1. 在eclipse中的maven工程中执行maven命令的步骤
  2. Stop单个Coroutine
  3. 8-cin cout PK scanf printf(速度快慢问题对比)
  4. Qt Customize QVariant
  5. udp调优经验
  6. fiddler手机抓包
  7. advance shading--光源的类型
  8. ajax数据流传参
  9. php快速获取所有的自定义常量用户常量
  10. [Training Video - 4] [Groovy] String Functions