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 ...
随机推荐
- jQuery动画效果实现
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 【nginx运维基础(7)】常用PHP开源程序的NginxRewrite示例
在写伪静态的时候,可以先用一个打印$_GET的PHP文件来测试,并且一定注意浏览器缓存,另外正则里如果有"{}",正则要用双引号包起来 dedecms location / { r ...
- python 模拟浏览器
想用python模拟浏览器访问web的方法测试些东西,有哪几种方法呢? 一类:单纯的访问web,不解析其js,css等. 1. urllib2 #-*- coding:utf-8 -* import ...
- 转TerreyLee AJAX入门系列2——ScriptManager的理解总结
ScriptManager的功能之一就是处理页面上局部更新,对于这点,我想大家都知道.但是他工作的原理到底是什么呢,这个暂且不从正面来回答. 我们这样想一下,目前能够真正实现局部刷新的就是js+xml ...
- jQuery $.post $.ajax用法
jQuery $.post $.ajax用法 jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异步请求 参数: url (Stri ...
- SetCapture、ReleaseCapture、GetCapture
正常情况下,鼠标指针位于哪个窗口区域内,鼠标消息就自动发给哪个窗口.如果调用了SetCapture,之后无论鼠标的位置在哪,鼠标消息都发给指定的这个窗口,直到调用ReleaseCapture或者调用S ...
- decode-string(挺麻烦的)
Java String作为参数传参是不会改变的,这个与常识的感觉不同. public String decodeString(String s) { s = ""; return ...
- javac编译过程
编译器把一种语言规范转化为另一种语言规范的这个过程需要哪些步骤:
- WebActivatorEx
using System; using NLog; using System.Web.Optimization; [assembly: WebActivatorEx.PreApplicationSta ...
- LA 3516 (计数 DP) Exploring Pyramids
设d(i, j)为连续子序列[i, j]构成数的个数,因为遍历从根节点出发最终要回溯到根节点,所以边界情况是:d(i, i) = 1; 如果s[i] != s[j], d(i, j) = 0 假设第一 ...