• hdu 5432 Pyramid Split(二分搜索)


    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.(1≤T≤100)
    
    Then T testcases follow.In each testcase print three lines :
    
    The first line contains one integers n(1≤n≤10000), the number of operations.
    
    The second line contains n integers A1,…,An(1≤i≤n,1≤Ai≤1000) represent the height of the ith pyramid.
    
    
    
    The third line contains n integers B1,…,Bn(1≤i≤n,1≤Bi≤100) 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
    10 7
    8
    702 983 144 268 732 166 247 569
    20 37 51 61 39 5 79 99
     
    Sample Output
    1 
    98
     
    Source
     
     1 #pragma comment(linker, "/STACK:1024000000,1024000000")
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<math.h>
     7 #include<algorithm>
     8 #include<queue>
     9 #include<set>
    10 #include<bitset>
    11 #include<map>
    12 #include<vector>
    13 #include<stdlib.h>
    14 using namespace std;
    15 #define ll long long
    16 #define eps 1e-10
    17 #define MOD 1000000007
    18 #define N 10006
    19 #define inf 1e12
    20 int n;
    21 double h[N];
    22 double w[N];
    23 double q;
    24 bool solve(double x){
    25     double sum=0;
    26     for(int i=0;i<n;i++){
    27         double wh=h[i]-x;
    28         if(wh>0){
    29             double p=wh/h[i];
    30             double ww=p*w[i];
    31             double ans=ww*ww*wh/3.0;
    32             sum+=ans;
    33         }
    34         
    35     }
    36     if(sum>=q) return true;
    37     return false;
    38 }
    39 int main()
    40 {
    41     int t;
    42     scanf("%d",&t);
    43     while(t--){
    44         scanf("%d",&n);
    45         for(int i=0;i<n;i++){
    46             scanf("%lf",&h[i]);
    47         }
    48         for(int i=0;i<n;i++){
    49             scanf("%lf",&w[i]);
    50         }
    51          q=0;
    52         for(int i=0;i<n;i++){
    53             q=q+w[i]*w[i]*h[i]/3.0;
    54         }
    55         q=q/2.0;
    56         double low=0;
    57         double high=1001;
    58         for(int i=0;i<100;i++){
    59             double mid=(low+high)/2;
    60             if(solve(mid)){
    61                 low=mid;
    62             }
    63             else{
    64                 high=mid;
    65             }
    66         }
    67         printf("%d
    ",(int)low);
    68     }
    69     
    70     return 0;
    71 }
    View Code
  • 相关阅读:
    dubbo的超时机制
    今天又遇到之前的问题,后端返回数据long到前端失真
    如何在一台机子上配置两个github
    当sum函数返回null时处理
    Linux中zookeeper安装
    Linux常用指令
    sql执行顺序
    固定时间刷新某个固定值 java
    docker基础
    python之CSS
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/4803717.html
Copyright © 2020-2023  润新知