zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    CollectionView Header And Footer 的使用
    UICollectionView 的添加自定义高度的区头
    利用SDWebImage 清理缓存
    iOS tableView 中 UITableView中UITableViewStyleGrouped和UITableViewStylePlain的区别
    关于tableview的分割线隐藏问题
    改变输入框的placehould的颜色 和边框颜色
    将代码在有xib得情况下设置到最底层(即执行顺序不是先执行xib) 将图片毛玻璃状态
    通知监听键盘高度变化 自适应键盘高度
    iOS 定义枚举
    iOS 快速存储到本地
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/4803717.html
Copyright © 2011-2022 走看看