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 ...
随机推荐
- 一天,python搞个分析NGINX日志的脚本
准备给ZABBIX用的. 统计接口访问字次,平均响应时间,4XX,5XX次数 以后可以再改进.. #!/usr/bin/env python # coding: utf-8 ############# ...
- Java并发包中常用类小结(一)
从JDK1.5以后,Java为我们引入了一个并发包,用于解决实际开发中经常用到的并发问题,那我们今天就来简单看一下相关的一些常见类的使用情况. 1.ConcurrentHashMap Concurre ...
- Android中使用HTTP和HttpClient进行通信
/** * 使用HTTP的Get方式进行数据请求 */ protected void httpGet() { /** * 进行异步请求 */ new AsyncTask<String, Void ...
- 【Linux高频命令专题(6)】mkdir
简述 用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 命令格式 mkdir [选项] 目录... 命令参数 -m, --mode=模式 ...
- SqlDataAdapter用法
SqlDataAdapter和SqlCommand区别: SqlCommand就是是命令了,可以用它来执行SQL命令: SqlDataAdapter就是数据适配器了,它是用于在数据源和数据集之间通讯的 ...
- s.charAt()
public class ish{public static void main(String[]args){ String s="call me ishmae";System.o ...
- QEvent大全,有中文解释
简述 QEvent 类是所有事件类的基类,事件对象包含事件参数. Qt 的主事件循环(QCoreApplication::exec())从事件队列中获取本地窗口系统事件,将它们转化为 QEvents, ...
- Lua表的构造及遍历
关于lua中的table,主要的困惑来自于table既可以当array用又可以当record用,有时候就会混淆不清. lua中的table貌似是用map来实现的,array是语法糖,一种特例.下面是l ...
- Git教程之管理修改(6)
Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件.你会问,什么是修改?比如你新增了一行,这就是一个修改,删除了一行,也是一个修改,更改了某些字符,也是一个修改,删了一些又加了 ...
- Xcode学习
http://www.cnblogs.com/ygm900/p/3488881.html