首页 技术 正文
技术 2022年11月14日
0 收藏 685 点赞 4,190 浏览 2242 个字

Problem DescriptionXiao 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.
 

InputFirst 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. 

OutputFor 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;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900