• P3291 [SCOI2016]妖怪


    传送门

    我数学的确白学了……这种题目竟然一点思路都没有……

    首先可以把每个妖怪看成二维平面上的一个点,那么每一个环境((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 eps 1e-8
    #define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
    #define fd(i,a,b) for(register int i=a,I=b-1;i>b;--i)
    using namespace std;
    #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    char buf[1<<21],*p1=buf,*p2=buf;
    template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
    int read(){
        int res,f=1;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;
    struct node{
    	int x,y;
    	node(){}
    	node(int x,int y):x(x),y(y){}
    	inline node operator -(const node &b){return node(x-b.x,y-b.y);}
    	inline double operator *(const node &b){return 1.0*x*b.y-1.0*y*b.x;}
    	inline bool operator <(const node &b)const{return x==b.x?y>b.y:x<b.x;}
    }p[N],st[N];
    int n,top;double ans=1e10,k;
    inline double K(const node &b){return -sqrt(1.0*b.y/b.x);}
    inline double xl(const node &a,const node &b){return a.x==b.x?-1e60:1.0*(a.y-b.y)/(a.x-b.x);}
    inline double calc(const node &b,double k){return fabs(k)<eps?1e20:1.0*b.x+b.y-1.0*b.x*k-1.0*b.y/k;}
    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);
    	fp(i,1,n){
    		while(top>=2&&(st[top]-st[top-1])*(p[i]-st[top])>0)--top;
    		st[++top]=p[i];
    	}
    	if(top==1)ans=calc(st[1],K(st[1]));
    	else{
    		k=K(st[1]);if(k>=xl(st[1],st[2]))cmin(ans,calc(st[1],k));
    		k=K(st[top]);if(k<=xl(st[top-1],st[top]))cmin(ans,calc(st[top],k));
    		cmin(ans,calc(st[top],xl(st[top-1],st[top])));
    	}
    	fp(i,2,top-1){
    		k=K(st[i]);
    		if(k<=xl(st[i-1],st[i])&&k>=xl(st[i],st[i+1]))cmin(ans,calc(st[i],k));
    		cmin(ans,calc(st[i],xl(st[i-1],st[i])));
    	}printf("%.4lf
    ",ans);return 0;
    }
    
  • 相关阅读:
    Java虚拟机
    Java集合常见面试题一
    5个新自动化测试框架,你值得了解
    Mock工具介绍
    空降,如何做好管理?
    QA在业务变动中如何维护测试用例?
    接口越权扫描平台初探
    程序员删代码泄愤,被判刑5个月,网友:年轻人不讲武德?!
    哪些 Python 库让你相见恨晚?
    两篇毕业论文致谢同一个女朋友?哈哈哈哈!
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/9998134.html
Copyright © 2020-2023  润新知