HDU 2289 Cup【高精度,二分】

Cup

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8942    Accepted Submission(s): 2744

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

The input consists of several test cases. The first line of input contains an integer T, indicating the num of test cases.
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

For each test case, output the height of hot water on a single line. Please round it to six fractional digits.

Sample Input

1

100 100 100 3141562

Sample Output

99.999024

Source

The 4th Baidu Cup final

Recommend

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289

分析:二分,对高度进行二分,然后我们知道圆台的公式为V=pi/3*(r*r+u*u+r*u)*h;然后可二分解决!这题精度比较坑爹,所以稍微注意点就好了!

下面给出AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 inline int read()
 5 {
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<‘0‘||ch>‘9‘)
 9     {
10         if(ch==‘-‘)
11             f=-1;
12         ch=getchar();
13     }
14     while(ch>=‘0‘&&ch<=‘9‘)
15     {
16         x=x*10+ch-‘0‘;
17         ch=getchar();
18     }
19     return x*f;
20 }
21 inline void write(int x)
22 {
23     if(x<0)
24     {
25         putchar(‘-‘);
26         x=-x;
27     }
28     if(x>9)
29     {
30         write(x/10);
31     }
32     putchar(x%10+‘0‘);
33 }
34 const double pi=acos(-1.0);
35 const double eps=1e-9;
36 double r,R,h,H,V;
37 inline double check(double r,double R,double h,double H)
38 {
39     double u=h/H*(R-r)+r;
40     return pi*1.0*(r*r+u*u+u*r)*h/3;
41 }
42 int main()
43 {
44     int n;
45     n=read();
46     while(n--)
47     {
48         scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
49         double L1=0.0;
50         double R1=100.0;
51         double mid;
52         while(L1+eps<R1)
53         {
54             mid=(L1+R1)/2;
55             double vv=check(r,R,mid,H);
56             if(fabs(vv-V)<=eps)
57                 break;
58             else if(vv>V)
59                 R1=mid-eps;
60             else L1=mid+eps;
61         }
62         printf("%.6lf\n",mid);
63     }
64     return 0;
65 }
时间: 2024-11-06 07:18:14

HDU 2289 Cup【高精度,二分】的相关文章

HDU 2289 Cup(二分可以,但是除了二分呢?)

这道题目,算数学题吗?算二分题吗?充其量算个水题吧... 首先,没有用二分,但是发现了一种新的解法来代替二分. 若果按照i从0,每次增加0.00000001来一直枚举到h的话,绝逼超时.枚举量太大了 但是可以分成两步来呀: #include<cstdio> #include<cmath> #define pai acos(-1.0) double r1,r2,h,v; double get_v(double temp) { double rr=r1+(r2-r1)*temp/h;

HDU 2289 Cup【二分】

<题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水的高度,然后根据几何计算出该高度下,水的上半径,然后计算出该高度下水的体积,在与实际水的体积进行比较,从而确定最终的答案. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 const doubl

HDU 2289 Cup

Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5597    Accepted Submission(s): 1787 Problem Description The WHU ACM Team has a big cup, with which every member drinks water. Now, we know th

【HDOJ】2289 Cup

二分.另外,圆台体积为v = PI*(r*r+r*R+R*R)*H/3.注意精度. 1 #include <cstdio> 2 #include <cmath> 3 4 #define exp 1e-9 5 6 const double PI = acos(-1.0); 7 8 int main() { 9 int t; 10 double r, R, H, v, lf, rt, mid, r0, nv; 11 scanf("%d", &t); 12 1

hdu 4185 Oil Skimming(二分匹配)

Oil Skimming Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 883    Accepted Submission(s): 374 Problem Description Thanks to a certain "green" resources company, there is a new profitable

HDU 4417 划分树+二分

题意:有n个数,m个询问(l,r,k),问在区间[l,r] 有多少个数小于等于k. 划分树--查找区间第k大的数.... 利用划分树的性质,二分查找在区间[l,r]小于等于k的个数. 如果在区间第 i 大的数tmp>k,则往下找,如果tmp<k,往上找. #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #incl

HDU 1281 棋盘游戏(二分匹配 与 删边)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 根据题目描述,什么是重要点?在求出最大匹配后,进行枚举,依次删边,看最大匹配数会不会发生改变,改变的话,那么该点就是重要点. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <

HDU 2119 Matrix 简单二分匹配

行做x集,列做y集,1就给该行该列连一条边,输出最大匹配边即可 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<set> using namespace std; #define N 105 int lef[N], pn;//lef[v]表示Y集的点v 当前连接的点 , pn为x点集的

HDU 3036 拆点二分最大流

Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 584    Accepted Submission(s): 117 Problem Description R's girl friend D is on military training somewhere near Harbin. She feels bad ever