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. 一个解决方案下的多个项目共享一个AssemblyInfo

    http://stackoverflow.com/questions/18963750/add-file-as-a-link-on-visual-studio-debug-vs-publish htt ...

  2. The Material Sourcing Process Failed To Create Picking Suggestions in INVTOTRX (文档 ID 2003806.1)

    In this Document Symptoms Cause Solution References Applies to: Oracle Inventory Management - Versio ...

  3. Java版本的删除指定目录及子目录下名叫“xxx.txt”的所有文件

    以前写过一个python版本的,但是在查找文件路径的时候出现错误,无法正确的获取到文件的路径,就造成无法删除该路径下的“xxx.txt”文件. 当时以为是windows版本系统的错误造成这个问题的,也 ...

  4. Sencha 基础Demo测试,三种showView的方法

    直接贴代码吧 Ext.define("build.controller.MainController",{ extend:"Ext.app.Controller" ...

  5. Self-Paced Training (2) - Docker Fundamentals

    Agenda- Building Images Dockerfile Managing Images and Containers Distributing Images on Docker Hub ...

  6. ↗☻【编写可维护的JavaScript #BOOK#】第8章 避免“空比较”

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  7. 使用powerdesigner 画图的详细说明

    一.概念数据模型概述 数据模型是现实世界中数据特征的抽象.数据模型应该满足三个方面的要求: 1)能够比较真实地模拟现实世界 2)容易为人所理解 3)便于计算机实现 概念数据模型也称信息模型,它以实体- ...

  8. TcxVerticalGrid 汇总

    赋值 AOrder.LoadSimpleFromFile(sDefineFile); grdRowFileDefine_PostalCode.Properties.Value := AOrder.Or ...

  9. Java + Excel 接口自动化

    最近项目比较悠闲,想找点事干,写了个 Excel 接口测试的 "框架" 以前用 python 写过一个,这次用 java, 应该说框架都不算,反正就是写了,能帮我解决问题就行. 当 ...

  10. REST API TESTING

    在敏捷开发过程中 每隔两周就是一个sprint,,, 在上个sprint中,任务就是REST API TESTING 因为以前没做过API 测试,不懂,然后经过询问查找 终于知道,需要发送请求,然后获 ...