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.(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
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\n", (int)low);
}
return 0;
}

  

二分一个高度h, 因为只需求整数部分,当(int)low == (int)high时,二分结束

hdu5432 二分的更多相关文章

  1. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  2. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  3. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  4. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  5. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  6. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

  7. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

  8. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  9. BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分

    [题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...

随机推荐

  1. 【python】time,datetime,string相互转换

    来源:http://essen.iteye.com/blog/1452098 #把datetime转成字符串 def datetime_toString(dt): return dt.strftime ...

  2. 51nod 1065 最小正子段和 (贪心)

    题目:传送门. 题意:中文题. 题解:求前缀和,并且标记每个数的下标,按照前缀和大小进行从小到大排序.随后进行遍历,如果满足下标data[i-1].id<data[i].id&& ...

  3. Yii里获取当前controller和action的id

    Yii里获取当前controller和action的id 在控制器里$name = $this->getId();  // controller$name = $action->id;  ...

  4. alias命令(使用命令别名)

    通过alias命令可以给一些命令定义别名,如,将长的难记住的命令起一个容易记住的别名,提高工作效率 alias -p 查看已有的别名列表 命名别名格式: alias 新命令名='原命令名 -参数/选项 ...

  5. 安装CocoaPods报错 - [!] The dependency `AFNetworking (~> 3.1.0)` is not used in any concrete target.

    今天新机装cocopods时,等安装完毕发觉出现[!] The dependency `AFNetworking (~> 3.1.0)` is not used in any concrete ...

  6. acpi参考网站

    1.acpi官网: http://www.acpi.info/

  7. Linux文件系统(inode、block……)

    内容源于<鸟哥的Linux私房菜> 认识 EXT2 文件系统 文件系统的特殊观察与操作 文件系统 superblock,inode,block superblock,inode,block ...

  8. struts标签<logic:iterate>的用法

    <logic:iterate>主要用来处理在页面上输出集合类,集合一般来说是下列之一: 1. java对象的数组 2. ArrayList.Vector.HashMap等 具体用法请参考s ...

  9. 攻城狮在路上(贰) Spring(四)--- Spring BeanFactory简介

    BeanFactory时Spring框架最核心的接口,它提供了高级IoC的配置机制,使管理不同类型的Java对象成为了可能.我们一般称BeanFactory为IoC容器.BeanFactory是Spr ...

  10. Spring XML配置文件示例(一)——<Servlet name>-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...