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. Session、Cookie与Token

    http协议是无状态协议 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到 ...

  2. ctfhub技能树—文件上传—文件头检查

    打开靶机 尝试上传一个php文件 抓包修改 放包 制作图片马 上传图片马,并修改文件类型为png 测试连接 查找flag 成功拿到flag

  3. linux系统中set、env、export关系

    set 用来显示shell变量(包括环境变量.用户变量和函数名及其定义),同时可以设置shell选项来开启调试.变量扩展.路径扩展等开关env 用来显示和设置环境变量export 用来显示和设置导出到 ...

  4. 【译】Async/Await(三)——Aysnc/Await模式

    原文标题:Async/Await 原文链接:https://os.phil-opp.com/async-await/#multitasking 公众号: Rust 碎碎念 翻译 by: Praying ...

  5. Podinfo,迷你的 Go 微服务模板

    ​项目介绍 Podinfo 是一个用 Go 制作的小型 web 应用程序,它展示了在 Kubernetes 中运行微服务的最佳实践. 它已实现的技术指标(截选自官方 README.md ): 里面每一 ...

  6. Linux下利用ifconfig命令查看和操纵网络接口

    为了说明这个问题,首先我们需要解释一下在Linux系统下"网络接口"的含义.通俗来讲,Linux中的所谓网络接口就是指本机的网卡,它相当于计算机的一台负责对网络进行收发数据的外设. ...

  7. 彻底解决小程序无法触发SESSION问题

    一.首先找到第一次发起网络请求的地址,将服务器返回set-cookie当全局变量存储起来 wx.request({ ...... success: function(res) { console.lo ...

  8. 浅析Redis与IO多路复用器原理

    为什么Redis使用多路复用I/O Redis 是跑在单线程中的,所有的操作都是按照顺序线性执行的,但是由于读写操作等待用户输入或输出都是阻塞的,所以 I/O 操作在一般情况下往往不能直接返回,这会导 ...

  9. charles安装使用乱码连手机等问题解决方案

    捣鼓半天终于安装好了,给大家分享下我的过程 1.安装, 正常网上安装即可,我安装了个有汉化包的,,推荐链接 安装方法下载破解版,安装即可 安装包地址:https://pan.baidu.com/s/1 ...

  10. pickle — Python object serialization

    pickle - Python object serialization  消息队列