HDU 5432 Pyramid Split
题意:有n个底面是正方形的四棱锥,用一个水平截面将所有四棱锥分成两半,要求上一半体积的和等于下一半,求水平截面的高度,输出整数部分。
解法:二分截面高度。比赛的时候二分写不明白了orz……
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
double const eps = 1e-3;
double a[10005], b[10005];
int n;
int cal(double mid)
{
double sum1 = 0.0, sum2 = 0.0;
for(int i = 0; i < n; i++)
{
if(mid > a[i])
{
sum2 += a[i] * b[i] * b[i] / 3.0;
continue;
}
double vsum = a[i] * b[i] * b[i] / 3.0;
double x = (a[i] - mid) * b[i] / a[i];
double lvsum = (a[i] - mid) * x * x / 3.0;
sum1 += lvsum;
sum2 += vsum - lvsum;
}
if(fabs(sum1 - sum2) < eps) return 0;
if(sum1 > sum2) return 1;
return -1;
}
int solve()
{
double l = 0.0, r = 1000.0;
double mid;
while((r-l)>= eps)
{
mid = (l + r) / 2.0;
int tmp = cal(mid);
if(tmp == 0) return mid;
else if(tmp == 1) l = mid + eps;
else r = mid - eps;
}
return mid;
}
int main()
{
int T;
while(~scanf("%d", &T))
{
while(T--)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%lf", &a[i]);
for(int i = 0; i < n; i++)
scanf("%lf", &b[i]);
printf("%d\n", (int)solve());
}
}
return 0;
}
while(r - l > 1)
{
LL mid = (l + r) >> 1;
if(judge(mid)) l = mid;
else
r = mid;
}
cout << l << endl;
/*贴一个实验室大神的二分模板*/
HDU 5432 Pyramid Split的更多相关文章
- hdu 5432 Pyramid Split 二分
Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...
- 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 ...
- HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))
http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...
- hdu5432 Pyramid Split
Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...
- hdu 5432
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- hdu5432 二分
Pyramid Split Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- CVPR2021|一个高效的金字塔切分注意力模块PSA
前言: 前面分享了一篇<继SE,CBAM后的一种新的注意力机制Coordinate Attention>,其出发点在于SE只引入了通道注意力,CBAM的空间注意力只考虑了局部区域的信息 ...
- 【二分法】 HDU 2446 Shell Pyramid
意甲冠军:非常多,形成一个金字塔球 文章x层 x*(x+1)/ 2 球 给你个S 金字塔的一层代表第一数字向下S球 它是其中 这层中的第几行 第几列 公式 1 : x*(x+1)*(x+2)/ 6 ...
- hdu 2191 珍惜现在,感恩生活
链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191 思路:多重背包模板题 #include <stdio.h> #include ...
随机推荐
- nginx模块开发(18)—日志分析
1.日志简介 nginx日志主要有两种:访问日志和错误日志.访问日志主要记录客户端访问nginx的每一个请求,格式可以自定义:错误日志主要记录客户端访问nginx出错时的日志,格式不支持自定义.两种日 ...
- POJ 1486 Sorting Slides(寻找必须边)
题意:找出幻灯片与编号唯一对应的情况 思路: 1:求最大匹配,若小于n,则答案为none,否则转2 (不过我代码没有事先判断一开始的最大匹配数是否<n,但这样也过了,估计给的数据最大匹配数一定为 ...
- this指针指向的彻底理解
首先必须要说的是,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象(这句话有些问题,后面会解释为什么会有问题,虽然 ...
- SDUT1500 Message Flood
以前做过的用的字典树,可是貌似现在再用超内存....求解释... 问了LYN用的map函数做的,又去小小的学了map函数.... http://wenku.baidu.com/view/0b08cec ...
- *[codility]Fish
https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...
- 一个酷炫的,基于HTML5,Jquery和Css的全屏焦点图特效,兼容各种浏览器
基于HTML5和CSS的焦点图特效,梅花图案的背景很有中国特色,而且还会动哦,效果超炫,推荐下载! 演示图 html代码 <!DOCTYPE html PUBLIC "-//W3C// ...
- C++:对象指针
对象指针概念:每一个对象在初始化后都会在内存中占有一定的空间.因此,既可以通过对象名访问, 也可以通过一个对象地址来访问一个对象.对象指针就是用于存放对象地址的变量. 声明对象指针的一般语法格式为:类 ...
- linux下手动安装apache详解
引自:http://blog.chinaunix.net/uid-28458801-id-4211258.html error1:出现以下错误时候,需要下载安装apr configure: error ...
- C#中控件的CheckState和Checked属性区别?
Checked 和CheckState都是检查控件选中状态,都能判断是否选中控件. 只是Checked 通过布尔判断(true & false): CheckState 通过枚举判断. che ...
- 關於NPOI的一點補充和示例
最近看到很多人分享NPOI的用法. 但是很多都不是完整示例或者並沒有實戰效果. 剛好最近有個VB.NET的項目有升級原有的oledb select sheet$的做法. 很明顯,NPOI有更好的穩定性 ...