HDU 2289 CUP 二分
Cup
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6684 Accepted Submission(s): 2062
Problem Description
The WHU ACM Team has a big cup, with which every member drinks water. Now, we know the volume of the water in the cup, can you tell us it height? The radius of the cup's top and bottom circle is known, the cup's height is also known.
Input
Each test case is on a single line, and it consists of four floating point numbers: r, R, H, V, representing the bottom radius, the top radius, the height and the volume of the hot water.
Technical Specification
1. T ≤ 20.
2. 1 ≤ r, R, H ≤ 100; 0 ≤ V ≤ 1000,000,000.
3. r ≤ R.
4. r, R, H, V are separated by ONE whitespace.
5. There is NO empty line between two neighboring cases.
Output
Sample Input
1
100 100 100 3141562
Sample Output
99.999024
题目大意:给出一个杯子的上下半径r,R,杯子的高度H,装入V升水,求水的高度
思路:二分或数学方法
二分
#include <stdio.h>
#include <math.h>
double r, R, H, V;
#define PI 3.1415926535897932
double vv(double h)
{
double x=r+(R-r)*h/H;
return (PI*h*(x*x+r*x+r*r)/3.0);
}
double f(double z, double y)
{
double mid;
while((y-z)>1e-)
{
mid=(z+y)/2.0;
if(vv(mid)<V)
z=mid;
else
y=mid;
}
return mid;
}
int main()
{
int a;
scanf("%d", &a);
while(a--)
{
scanf("%lf%lf%lf%lf", &r, &R, &H, &V);
printf("%lf\n", f(,H));
}
return ;
}
HDU 2289 CUP 二分的更多相关文章
- HDU 2289 Cup【高精度,二分】
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2289 Cup【二分】
<题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水 ...
- hdu 2289 要二分的杯子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...
- hdu 2289 Cup (二分法)
http://acm.hdu.edu.cn/showproblem.php?pid=2289 二分法解题. 这个题很恶心...一开始测试样例都不能过,这个π一开始取3.1415926结果是99.999 ...
- HDU 2289 Cup
Cup Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2289 Cup(可以二分法,但是除了它的一半?)
这道题目.运营商做数学题?算上两个子主题做?顶多算一个水主要议题... 首先,没有实际的二分法,但是,我们发现了一个新的解决方案,以取代二分法. 若果按照i从0,每次添加0.00000001我一直枚举 ...
- 二分搜索 HDOJ 2289 Cup
题目传送门 /* 二分搜索:枚举高度,计算体积与给出的比较. */ #include <cstdio> #include <algorithm> #include <cs ...
- Cup HDU - 2289
题目传送门:https://vjudge.net/problem/HDU-2289 题意:有一个上口小于底部的圆台形水杯,告诉我们水的体积求水高度. 思路:利用高中数学知识求rr然后二分求h,具体化简 ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
随机推荐
- 夺命雷公狗—express—1—express的配置方法和目录结构分析
- ajax讲解:“创建用户”和“用户登录”练习
ajax可以在不重新加载整个网页的情况下,对网页的某部分进行更新. 传统的网页(不使用 AJAX)如果需要更新内容,必须重载整个网页页面. 接下来,将以例子的形式进行讲解 例一:创建用户 ...
- linux强制umount设备的方法
假如挂载时使用了:mount /dev/sda1 /mnt/sda1 #查找占用设备的pid fuser -m /mnt/sda1 #假如此时得到的pid为12345 kill -9 12345 um ...
- 运行eclipse提示 The requested resource () is not available.
不识别web-inf目录,把文件放在Webcontent下就可以运行. 放在其他文件夹里也可以识别.
- android 应用架构随笔五(ActionBar与侧滑菜单DrawerLayout)
ActionBar(V7)的添加非常简单,只需要在AndroidManifest.xml中指定Application或Activity的theme是Theme.Holo或其子类就可以了,在Androi ...
- sql多表查询(out join,inner join, left join, right join)
left join以左表为基准显示所有左表的信息,在on中有符合条件的其他表也显示出来 right join则相反 inner join的只显示on中符合条件的 1 使用多个表格 在「world」资料 ...
- yum源的修改
源路径: /etc/yum.repos.d/ 配置文件: 网络搜索 CentOS-Base.repo(默认) 设备搜索 CentOS-Media.repo 将CentOS-Base.repo移除或改名 ...
- mount源码分析 【转】
转自:http://blog.chinaunix.net/uid-10769062-id-3230811.html Busybox- 在util-linux/mount.c的line:1609行首先映 ...
- 坑爹的VS2012
2.2.2.如果卸载 Visual Studio 2010 Service Pack 1,则必须先重新安装 Visual Studio 2010,然后才能再次安装 SP1 如果卸载 Visual St ...
- php socket通信(tcp/udp)
注意 1.在socket_bind的时候ip地址不能真回环地址如127.0.0.1 2.server.php后台跑起来的时候 nohup php server.php > /var/tmp/a. ...