• hdu5432 二分


    Pyramid Split

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 104    Accepted Submission(s): 50


    Problem Description
    Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which have square undersides,let's call them pyramids.

    Anyone of them can be defined by the square's length and the height,called them width and height.

    To easily understand,all the units are mile.Now Ming has n pyramids,there height and width are known,Xiao Ming wants to make them again to get two objects with the same volume.

    Of course he won't simply melt his pyramids and distribute to two parts.He has a sword named "Tu Long" which can cut anything easily.

    Now he put all pyramids on the ground (the usdersides close the ground)and cut a plane which is parallel with the water level by his sword ,call this plane cutting plane.

    Our mission is to find a cutting plane that makes the sum of volume above the plane same as the below,and this plane is average cutting plane.Figure out the height of average cutting plane.
     
    Input
    First line: T, the number of testcases.(1T100)

    Then T testcases follow.In each testcase print three lines :

    The first line contains one integers n(1n10000), the number of operations.

    The second line contains n integers A1,,An(1in,1Ai1000) represent the height of the ith pyramid.



    The third line contains n integers B1,,Bn(1in,1Bi100) represent the width of the ith pyramid.
     
    Output
    For each testcase print a integer - **the height of average cutting plane**.

    (the results take the integer part,like 15.8 you should output 15)
     
    Sample Input
    2
    2
    6 5
    107
    8
    702 983 144 268 732 166 247 569
    20 37 51 61 39 5 79 99
     
    Sample Output
    1
    98
     
    思路:设分割平面的高度为x,可以简单推出x以上的椎体的体积为:((B * B) / (A * A)) * (A - x)^3 * 1 / 3
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    int a[10005], b[10005], n;
    typedef long long ll;
    double sum;
    
    bool check(double x) {
        double now = 0;
        for(int i = 1; i <= n; ++i)
            if(a[i] >= x)
            now += ((b[i] * b[i] * 1.0) / (a[i] * a[i])) * (a[i] - x) * (a[i] - x) * (a[i] - x);
        if(now < sum) return true;
        else return false;
    }
    
    int main()
    {
        int _;
        scanf("%d", &_);
        while(_ --)
        {
            int H = 0;
            scanf("%d", &n);
            for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); if(a[i] > H) H = a[i]; }
            for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
            sum = 0;
            for(int i = 1; i <= n; ++i) sum += b[i] * b[i] * a[i];
            sum /= 2;
            double low = 0, high = H;
            while((int)low != (int)high)
            {
                double h = (low + high) / 2;
                if(check(h)) high = h;
                else low = h;
            }
            printf("%d
    ", (int)low);
        }
        return 0;
    }
    

      

    二分一个高度h, 因为只需求整数部分,当(int)low == (int)high时,二分结束
  • 相关阅读:
    Android 性能测试_Monkey 实践
    Linux下 运行Jmeter (含一个jmeter简单示例)
    IOS测试-Fastmonkey
    iOSApp -Monkey测试
    如何用monkey测试IOS
    MVC系列开篇:(我的第一片博文)
    ASP.NET MVC 使用Swagger需要注意的问题!!!
    Urlparse模块
    从0到1:微信后台系统的演进之路(转自INFOQ)
    什么是商业模式?产品模式、用户模式、推广模式,最后是收入模式(转)
  • 原文地址:https://www.cnblogs.com/orchidzjl/p/4803697.html
Copyright © 2020-2023  润新知