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

这题用到了锥体的计算公式以及二分,二分的判断条件要注意,另外,向下取整可以用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-8
double 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;
}

hdu5432 Pyramid Split的更多相关文章

  1. hdu 5432 Pyramid Split 二分

    Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...

  2. hdu 5432 Pyramid Split(二分搜索)

    Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...

  3. HDU 5432 Pyramid Split

    题意:有n个底面是正方形的四棱锥,用一个水平截面将所有四棱锥分成两半,要求上一半体积的和等于下一半,求水平截面的高度,输出整数部分. 解法:二分截面高度.比赛的时候二分写不明白了orz…… 代码: # ...

  4. hdu5432 二分

    Pyramid Split Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  5. CVPR2021|一个高效的金字塔切分注意力模块PSA

    ​ 前言: 前面分享了一篇<继SE,CBAM后的一种新的注意力机制Coordinate Attention>,其出发点在于SE只引入了通道注意力,CBAM的空间注意力只考虑了局部区域的信息 ...

  6. 『计算机视觉』FPN:feature pyramid networks for object detection

    对用卷积神经网络进行目标检测方法的一种改进,通过提取多尺度的特征信息进行融合,进而提高目标检测的精度,特别是在小物体检测上的精度.FPN是ResNet或DenseNet等通用特征提取网络的附加组件,可 ...

  7. 空间金字塔池化(Spatial Pyramid Pooling,SPP)

    基于空间金字塔池化的卷积神经网络物体检测 原文地址:http://blog.csdn.net/hjimce/article/details/50187655 作者:hjimce 一.相关理论 本篇博文 ...

  8. 【HEVC帧间预测论文】P1.6 A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence

    A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence <HEVC标准介绍.HEVC帧间预测论文笔记&g ...

  9. 表值函数与JS中split()的联系

    在公司用云平台做开发就是麻烦 ,做了很多功能或者有些收获,都没办法写博客,结果回家了自己要把大脑里面记住的写出来. split()这个函数我们并不陌生,但是当前台有许多字段然后随意勾选后的这些参数传递 ...

随机推荐

  1. MySQL 使用MD5对数据进行加密

    数据库MD5加密 -- ================ 测试 MD5 加密 ============== CREATE TABLE `testmd5`( id INT(11) NOT NULL AU ...

  2. 【Linux】配置ssh留下的一些思考和大坑解决办法

    今天传包突然有问题,结果发现是ssh出现了问题,密钥也在里面,都是正常的,但是还有什么问题呢? 后来总结下需要注意点: 1.最开始你要检查.ssh/  这个文件夹的权限,看下权限是否为700或者为75 ...

  3. 以事实驳斥:改进你的c#代码的5个技巧(四)

    测试使用的环境:vs2019+.net core3.1 原文地址:https://www.cnblogs.com/hhhnicvscs/p/14296715.html 反驳第一条:如何检查代码中的空字 ...

  4. CVE-2018-1273 Spring Data Commons 远程命令执行漏洞复现

    一.漏洞描述 Spring Data是一个用于简化数据库访问,并支持云服务的开源框架,Spring Data Commons是Spring Data下所有子项目共享的基础框架.Spring Data ...

  5. 源代码增强的一点说明(souce code enhance )

    souce code enhance 分为显式和隐式两种. 下面以显式创建为例子: 1.在ABAP编辑器中, 打开想要编辑的程序,切换到可编辑模式 2.在源代码中的指定位置右键,弹出菜单,选择 Enh ...

  6. 使用Logback日志

    使用Logback日志 spring boot内部使用Logback作为日志实现的框架. Logback和log4j非常相似,如果你对log4j很熟悉,那对logback很快就会得心应手. logba ...

  7. 浅析鸿蒙中的 Gn 与 Ninja(一)

    目录: Ninja简介 make 的 3 个特性 举例说明Ninja 的用法 如何向构建工具 Ninja 描述构建图 后记 鸿蒙系统的编译构建是基于 Gn 和 Ninja 完成的,那么 Gn 和 Ni ...

  8. mysqldump导出数据库导入数据库

    使用mysqldump命令导出数据库,格式如下,请按实际要求对参数进行替换: mysqldump -u 用户名 -p 数据库名 > 导出的文件名 比如导出数据库business_db: mysq ...

  9. Mac下IDEA激活Jrebel

    第一步:在idea中下载jrebel,过程省略 第二步:配置反向代理工具 Windows 版:http://blog.lanyus.com/archives/317.html MAC 版: 安装hom ...

  10. RestTemplate post请求

    以前一开始用原生的http请求,那叫一个累,后来找到一个第三方的工具包,用起来是真的舒服,不过有一说一,第三方工具包依赖性真的强,除非和组长商量过,不然能少用,还是少用点.话说搞微服务的肯定少不了和H ...