Pyramid Split

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=629&pid=1001

Description

小明是城会玩,他有很多底面是正方形的黄金锥体,我们称之为金字塔,它由高度和底面正方形边长可以确定,分别称之为金字塔的高和宽。
为了便于理解,单位统一取米。现在小明有nn个金字塔,已知它们的高和宽,小明打算重铸,想将它重铸成两个体积一样的物体。
当然,小明是城会玩,不会简单的把所有金字塔融了再分,他有一把屠龙刀,该刀削金如泥。
他现在把所有金字塔正放(即底面贴地放)在水平地面上,用屠龙刀切割一个平面,该平面与水平面平行,称之为割平面。
我们的任务是找到一个这样的割平面,使得这个割平面上方的体积之和等于下方的体积之和,该割平面称之为平均割平面。求平均割平面的高度。

Input

第一行输入一个整数TT,表示TT组数据( 1 \leq T \leq100 )(1≤T≤100)。
每组数据有三行,第一行有一个整数nn,表示金字塔的个数( 1 \leq n \leq 10000 )(1≤n≤10000)。
第二行有nn个整数A_iA​i​​,分别表示第ii个金字塔的高度( 1 \leq A_i \leq 1000)(1≤A​i​​≤1000)。
第三行有nn个整数B_iB​i​​,分别表示第ii个金字塔的宽度(1 \leq B_i \leq 100 )(1≤B​i​​≤100)。

Output

对于每组数据,输出平均割平面的高度,取整数部分(如15.8请输出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

HINT

题意

题解:

高度是满足二分性质的,所以直接二分答案就好了

最后把答案的值的小数部分略去就好了

注意,这个题的hdu的数据比较弱

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 500001
#define mod 1001
#define eps 1e-7
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* double getlen(double x,double h,double h2)
{
if(h2>=h)
return h;
return x*h2/h;
}
double getarea(double x,double h)
{
return x*x*h;
}
double h[];
double x[];
int n;
double check(double mid)
{
double s2 = ;
for(int i = ; i <= n ; ++ i)
{
if(mid >= h[i]) continue;
else
{
double c = h[i] - mid;
double v1 = (x[i]*x[i])*(h[i]-mid)*(h[i]-mid)*(h[i]-mid)/(h[i]*h[i]);
s2 += v1;
}
}
return s2;
}
int main()
{
int t=read();
while(t--)
{
memset(h,,sizeof(h));
memset(x,,sizeof(x));
n=read();
for(int i=;i<=n;i++)
scanf("%lf",&h[i]);
for(int i=;i<=n;i++)
scanf("%lf",&x[i]);
double s = ;
for(int i=;i<=n;i++)
s+=getarea(x[i],h[i]);
s/=2.0;
double mid;
double L = 0;
double R = ;
while((R-L) > eps)
{
double mid = (L+R)/2.0;
if(check(mid) > s) L = mid;
else R = mid;
}
int ans = L;
printf("%d\n",ans);
}
}

hdu 5432 Pyramid Split 二分的更多相关文章

  1. HDU 5432 Pyramid Split

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

  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 3586 Information Disturbing (二分+树形dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3586 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...

  4. HDU 5726 GCD (RMQ + 二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...

  5. HDU 5715 XOR 游戏 二分+字典树

    XOR 游戏 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5715 Description 众所周知,度度熊喜欢XOR运算(XOR百科). 今天,它 ...

  6. HDU 5699 货物运输 二分

    货物运输 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5699 Description 公元2222年,l国发生了一场战争. 小Y负责领导工人运输物 ...

  7. HDU 3081 最大流+二分

    Marriage Match II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. hdu 1281 棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    M ...

  9. hdu 1853 Cyclic Tour (二分匹配KM最小权值 或 最小费用最大流)

    Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total ...

随机推荐

  1. Android开发之错误:elicpse运行时弹出Running Android Lint has encountered a problem failed, nullpointerexception

    昨天安装了下Android Studio,把SDK路径指向了ADT目录下的SDK目录.同时FQ出去更新了下SDK.然后今天运行eclipse的时候,弹出错误,同时在工程的名称处有错误提醒,但是代码中没 ...

  2. poj3034Whac-a-Mole(dp)

    链接 状态转移好想 不过有坑 大家都犯的错误 我也会犯 很正常 就是锤子可以移到n*n以外  要命的是我只加了5 以为最多不会超过5  WA了N久  才想到 上下两方向都可以到5 所以最多加10 以时 ...

  3. poj 3414 Pots ( bfs )

    题目:http://poj.org/problem?id=3414 题意:给出了两个瓶子的容量A,B, 以及一个目标水量C, 对A.B可以有如下操作: FILL(i)        fill the ...

  4. Codeforces Round #306 (Div. 2)

    A. Two Substrings You are given string s. Your task is to determine if the given string s contains t ...

  5. 一滴一点vim(学习+备忘)

    普通模式: h j k l 分别是左下上右方式移动: :w 保存修改 :q 推出 :wq 保存修改并退出 :q! 放弃修改强制推出 x 删除光标所在位置字符 i 在光标所以位置插入字符 删除类命令: ...

  6. log4net使用的一点心得

    关于使用log4net的文章很多,把自己在使用中查到的文章列一下. log4net 可以存在很多地方 比如console,数据库.邮箱.文本等等.我要实现的是 所有的日志都记录到html文件中,可以按 ...

  7. 【暑假】[深入动态规划]UVa 10618 Fun Game

    UVa 10618 Fun Game 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36035 思路:   一圈人围坐 ...

  8. MFC定时器

    比较简单,在程序中可以找到原型. 在程序中我们经常要使用定时刷新的功能,典型的应用是在信息管理系统中表单要跟着数据库中的数据变动.MFC提供了定时器来完成这个功能. ================= ...

  9. WEB开发总结(持续更新。。。)

    近期开始搞搞web的东西,觉得有必要把遇到的问题总结一下,就在这里当做个笔记本吧. 1.用maven建立的web工程,在运行的时候,右键找不到“Run on server”菜单: 可以在命令提示行中, ...

  10. HW7.4

    public class Solution { public static void main(String[] args) { int[] employee = new int[8]; int[] ...