hdu5432 Pyramid Split
来源:互联网 发布:免费申请淘宝账号 编辑:程序博客网 时间:2024/04/27 22:34
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 hasn 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.
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
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)
ThenT testcases follow.In each testcase print three lines :
The first line contains one integersn(1≤n≤10000) , the number of operations.
The second line containsn integers A1,…,An(1≤i≤n,1≤Ai≤1000) represent the height of the ith pyramid.
The third line containsn integers B1,…,Bn(1≤i≤n,1≤Bi≤100) represent the width of the ith pyramid.
Then
The first line contains one integers
The second line contains
The third line contains
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)
(the results take the integer part,like 15.8 you should output 15)
Sample Input
226 510 78702 983 144 268 732 166 247 56920 37 51 61 39 5 79 99
Sample Output
198这题用到了锥体的计算公式以及二分,二分的判断条件要注意,另外,向下取整可以用printf("%d",(int)a);或者printf("%.0f",floor(a));
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<string>#include<algorithm>using namespace std;#define ll long long#define inf 0x7fffffff#define maxn 10050#define eps 1e-8double s[maxn],w[maxn],h[maxn],v[maxn];int n,m;double cal(double h1){ int i,j; double num=0,ans; for(i=1;i<=n;i++){ if(h1>h[i]){ num+=v[i]; } else{ ans=1-(h[i]-h1)*(h[i]-h1)*(h[i]-h1)/(h[i]*h[i]*h[i]); num+=v[i]*ans; } } return num;}int main(){ int i,j,T; double sum,maxx; double l,r,mid; scanf("%d",&T); while(T--) { scanf("%d",&n); sum=0;maxx=0; for(i=1;i<=n;i++){ scanf("%lf",&h[i]); maxx=max(maxx,h[i]); } for(i=1;i<=n;i++){ scanf("%lf",&w[i]); s[i]=w[i]*w[i]; v[i]=s[i]*h[i]/3; sum+=v[i]; } l=0;r=maxx; while(r-l>eps){ mid=(l+r)/2; if(cal(mid)*2>sum){ r=mid; } else l=mid; } printf("%d\n",(int)mid); } return 0;}
0 0
- 二分 hdu5432 Pyramid Split
- hdu5432 Pyramid Split
- ACM hdu5432 Pyramid Split
- HDU5432-Pyramid Split
- hdu5432 Pyramid Split(二分)
- HDU 5432 Pyramid Split
- hdu 5432Pyramid Split
- HDU 5432 Pyramid Split
- HDU 5432 Pyramid Split 二分
- HDOJ 5432 Pyramid Split(二分)
- HDU 5432 BC - Pyramid Split(二分 + 模拟)
- hdu 5432 Pyramid Split(二分)
- hdu 5432 Pyramid Split【二分查找】
- HDU 5432 Pyramid Split(浮点数二分查找)
- BestCoder55 hdu5432 二分
- Pyramid + mod_wsgi
- Shell Pyramid
- Gaussian pyramid
- Chromium的Plugin进程启动过程分析
- BackboneJs入门学习[06]—Collection初探
- java中接口有什么作用?请创建一个接口(举例)
- java编程---万年历
- Dart基础学习01--走近Dart
- hdu5432 Pyramid Split
- 通达OA 小飞鱼工作流在线培训教程(九)流程设计(第一部分)
- 第二周项目3 体验复杂度(2)
- [人月神话]读书笔记10--20年后的人月神话(The Mythical Man-Month after 20 Years)
- 2015长春网络赛1001 - HDU5433 - Alisha’s Party (模拟)
- Landslide win for PAP in general election
- java代码中执行shell或调用系统命令
- Unity T4M
- 软工之概况