码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5432 Pyramid Split(二分搜索)

时间:2015-09-12 22:22:49      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:

Problem Description
Xiao Ming is a citizen whos good at playing,he has lots of gold cones which have square undersides,lets call them pyramids.

Anyone of them can be defined by the squares 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 wont 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\n",(int)low);
68     }
69     
70     return 0;
71 }
View Code

 

hdu 5432 Pyramid Split(二分搜索)

标签:

原文地址:http://www.cnblogs.com/UniqueColor/p/4803717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!