zoukankan      html  css  js  c++  java
  • HDU4355 三分查找

    /*
     * 三分查找
     */
    #include<cstdio>
    #include<cmath>
    #define eps 1e-6

    //typedef __int64 LL;


    int n;
    double x[50005], w[50005];

    double func(double y){
        double res=0;
        for(int i=0;i<n;i++){
            double a=y-x[i];
            a=a<0?-a:a;
            res+=a*a*a*w[i];
        }
        return res;
    }

    int main(){
        int T;
        scanf("%d",&T);
        for(int t=1;t<=T;t++){
            scanf("%d",&n);
            for(int i=0;i<n;i++){
                scanf("%lf%lf",&x[i],&w[i]);
            }
            double l=x[0],r=x[n-1],mid,mmid;
            while(r-l>eps){
                mid=(l+r)/2.0;
                mmid=(mid+r)/2.0;
                if(func(mid)-func(mmid)>eps){
                    l=mid;
                }
                else{
                    r=mmid;
                }
            }

            printf("Case #%d: %lld ",t,(long long)(func(r)+0.5));

            //hdu要用int64

        }
    }


  • 相关阅读:
    buuctf-misc 一叶障目
    攻防世界-web ics-05
    攻防世界-web ics-06
    攻防世界-web NewsCenter
    攻防世界-web upload1
    攻防世界-web unserialize3
    攻防世界-web PHP2
    攻防世界-web2
    gitlab常用命令
    javascript编程风格
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703240.html
Copyright © 2011-2022 走看看