hdu 5432 Pyramid Split(二分搜索)
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.
First line: T, the number of testcases.(≤T≤) Then T testcases follow.In each testcase print three lines : The first line contains one integers n(≤n≤), the number of operations. The second line contains n integers A1,…,An(≤i≤n,≤Ai≤) represent the height of the ith pyramid. The third line contains n integers B1,…,Bn(≤i≤n,≤Bi≤) represent the width of the ith pyramid.
For each testcase print a integer - **the height of average cutting plane**. (the results take the integer part,like 15.8 you should output )
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 10006
#define inf 1e12
int n;
double h[N];
double w[N];
double q;
bool solve(double x){
double sum=;
for(int i=;i<n;i++){
double wh=h[i]-x;
if(wh>){
double p=wh/h[i];
double ww=p*w[i];
double ans=ww*ww*wh/3.0;
sum+=ans;
} }
if(sum>=q) return true;
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf",&h[i]);
}
for(int i=;i<n;i++){
scanf("%lf",&w[i]);
}
q=;
for(int i=;i<n;i++){
q=q+w[i]*w[i]*h[i]/3.0;
}
q=q/2.0;
double low=;
double high=;
for(int i=;i<;i++){
double mid=(low+high)/;
if(solve(mid)){
low=mid;
}
else{
high=mid;
}
}
printf("%d\n",(int)low);
} return ;
}
hdu 5432 Pyramid Split(二分搜索)的更多相关文章
- hdu 5432 Pyramid Split 二分
Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...
- HDU 5432 Pyramid Split
题意:有n个底面是正方形的四棱锥,用一个水平截面将所有四棱锥分成两半,要求上一半体积的和等于下一半,求水平截面的高度,输出整数部分. 解法:二分截面高度.比赛的时候二分写不明白了orz…… 代码: # ...
- HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))
http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...
- Trucking(HDU 2962 最短路+二分搜索)
Trucking Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu5432 Pyramid Split
Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...
- hdu 5432
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- hdu5432 二分
Pyramid Split Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- CVPR2021|一个高效的金字塔切分注意力模块PSA
前言: 前面分享了一篇<继SE,CBAM后的一种新的注意力机制Coordinate Attention>,其出发点在于SE只引入了通道注意力,CBAM的空间注意力只考虑了局部区域的信息 ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Sonar入门(五):使用 Sonar 进行代码质量管理
Sonar 概述 Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具. 与持续集成工具(例如 Hudson/Jenkins ...
- [CSAPP笔记][第十章 系统级I/O]
第十章 系统级I/O 输入/输出(I/O) : 是指主存和外部设备(如磁盘,终端,网络)之间拷贝数据过程. 高级别I/O函数 scanf和printf <<和>> 使用系统级I ...
- C#基础:关键字和数据类型
[关键字] #region 和 #endregion 关键字可以折叠代码 checked 用于整型算术运算时控制当前环境中的溢出检查 unchecked 操作符用于整型算术运算时控制当前环境中的 ...
- c# 鼠标操作
1#region 3using System; 4using System.Runtime.InteropServices; 6#endregion 8namespace Windows.Forms. ...
- 《第一行代码》学习笔记2-Android开发特色
1.四大组件:活动(Activity),服务(Service),广播接收器(Broadcast Receiver),内容提供器(Content Provider). Activity:应用中看得到的东 ...
- 【Nutch基础教程之七】Nutch的2种运行模式:local及deploy
在对nutch源代码运行ant runtime后,会创建一个runtime的目录,在runtime目录下有deploy和local 2个目录. [jediael@jediael runtime]$ l ...
- 浅析 JavaScript 组件编写
之前因项目需要也编写过一些简单的JS组件,大多是基于JQuery库的,一直也没有过总结,导致再次写到的时候还去Google, 近日看到一个文章总结的挺好,拿过整理一下做个备忘. 此次同样是基于jque ...
- [Mugeda HTML5技术教程之18]如何在Android应用中使用Mugeda动画内容
1.简介 本文主要介绍如何在Android应用程序中使用Mugeda动画.Mgeda动画是标准HTML5格式的动画,在Android应用程序中可以使用WebView来加载Mugeda动画.动画内容本身 ...
- CSS优先级、引入方式、Hack
优先级 important > 内联(1,0,0,0) > id(1,0,0) > class(1,0) > element(1) > *通配符 css引入方式 方式一: ...
- 拉姆达表达式 追加 条件判断 Expression<Func<T, bool>>
public static class PredicateBuilder { /// <summary> /// 机关函数应用True时:单个AND有效,多个AND有效:单个OR无效,多个 ...