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. Fail2ban工具使用

    Fail2ban ​ fail2ban扫描日志文件并且可以识别禁用某些多次尝试登录的IP,通过更新系统的防火墙规则来实现拒绝该IP连接,也可以配置禁用的时间.fail2ban提供了一些常用软件默认的日 ...

  2. .NET斗鱼直播弹幕客户端(2021)

    .NET斗鱼直播弹幕客户端(2021) 离之前更新的两篇<.NET斗鱼直播弹幕客户端>已经有一段时间,近期有许多客户向我反馈刚好有这方面的需求,但之前的代码不能用了--但网上许多流传的No ...

  3. 3610:20140827:161308.483 No active checks on server: host [192.168.1.10] not found

    3610:20140827:161308.483 No active checks on server: host [192.168.1.10] not found

  4. 使用msys2在window下构建和使用Linux的软件

    目录 前言 安装 使用 总结 前言 在window下构建Linux编译环境是很常见的,以前用过mingw弄过差不多的环境. 但是使用msys2后就根本停不下来咯,太好用咯. 安装 去官网下载吧,安装跟 ...

  5. rename命令和批量重命名

    本文为转载文章,转发自 https://blog.csdn.net/GGxiaobai/article/details/53507454 早期版本的rename是C语言版本,如今新的Ubuntu中采用 ...

  6. Jquery实现对Array数组实现类似Linq的Lambda表达式的Where方法筛选

    平时使用Linq,习惯了Lambda表达式,用着非常顺手,奈何在Jquery里面不能这样用,只能循环一个个判断.趁空闲时间找了找,自己写了这样的扩展方法.目前写出了三种方案,没有比较性能,觉得都可以用 ...

  7. [CPP] STL 简介

    STL 即标准模板库(Standard Template Library),是 C++ 标准库的一部分,里面包含了一些模板化的通用的数据结构和算法.STL 基于模版的实现,因此能够支持自定义的数据结构 ...

  8. Java运算符及包机制

    Java中的运算符及包机制 算术运算符:+ - * / % ++ -- 赋值运算符:=,+=,-=,*=,/= 关系运算符:>,<,>=,<=,==,!=,instanceof ...

  9. OpenCV 和 Dlib 人脸识别基础

    00 环境配置 Anaconda 安装 1 下载 https://repo.anaconda.com/archive/ 考虑到兼容性问题,推荐下载Anaconda3-5.2.0版本. 2 安装 3 测 ...

  10. Kubernetes调整Node节点快速驱逐pod的时间

    在高可用的k8s集群中,当Node节点挂掉,kubelet无法提供工作的时候,pod将会自动调度到其他的节点上去,而调度到节点上的时间需要我们慎重考量,因为它决定了生产的稳定性.可靠性,更快的迁移可以 ...