zoukankan      html  css  js  c++  java
  • Swimming Balls

    Swimming Balls
    https://vjudge.net/contest/318752#problem/J
    如果直接算,各种球的情况都不清楚,因为放一个球之后,水位的变化也会影响之前放入的球,不如,二分最终的水位高度,这样每个球的贡献就有了

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #define inf 2147483647
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(int i=a;i<=b;++i)
    //by war
    //2019.8.16
    using namespace std;
    int T,n;
    double L,x,y,mid,W,D,V,w[N],r[N],eps=1e-10,ans,pai=3.141592653589793;
    void in(int &x){
        int y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(int x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    double v(double r){
        return 4.0000000/3.00000000*pai*r*r*r;
    }
    
    double deal(double h,int i){
        return pai*(r[i]*r[i]*h-h*h*h/3.0);
    }
    
    double lj(double x,int i){
        if(x-r[i]>eps)
            return v(r[i])/2.0+deal(min(r[i],x-r[i]),i);
        return v(r[i])/2.0-deal(r[i]-x,i);
    }
    
    bool check(double x){
        double t=V;
        For(i,1,n){
            if(1.0000000-w[i]>eps)
                t+=min(v(r[i])*w[i],lj(x,i));
            else
                t+=lj(x,i);
        }
        if(t/W/L-x>eps)
            return 1;
        return 0;
    }
    signed main(){
        in(T);
        while(T--){
            in(n);
            cin>>W>>L>>D>>V;
            if(V<eps){
                puts("0.0000000000");
                continue;
            }
            For(i,1,n)
                cin>>r[i]>>w[i];
            x=0;y=D+eps;
            while(y-x>eps){
                mid=(x+y)/2.0;
                if(check(mid))
                    x=mid;
                else
                    y=mid;
            }
            printf("%.10f
    ",mid);
        }
        return 0;
    }
  • 相关阅读:
    线程 定时任务 实现思路
    Days Floating In ShenZhen(1)
    由于未能找到具有自动生成的控件来引发回发事件,导致发生错误
    在ASP.NET中使用AJAX.NET (转译自MSDN)(二)
    Every Time I Wake up I want sleep more
    漂泊在深圳的日子2
    512今日历程
    流金岁月
    对自己的思考
    关于绑定自动生成的下拉式菜单的错误
  • 原文地址:https://www.cnblogs.com/war1111/p/11375679.html
Copyright © 2011-2022 走看看