HDU 2289 Cup【二分】

<题目链接>

题目大意:

一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少。

解题分析:

就是简单的二分答案,二分枚举杯中水的高度,然后根据几何计算出该高度下,水的上半径,然后计算出该高度下水的体积,在与实际水的体积进行比较,从而确定最终的答案。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4
 5 const double PI=acos(-1.0);
 6 const double eps=1e-9;
 7 double R,r,H,v;
 8
 9 double vol(double h){
10     double rtop=(H*r+h*(R-r))*1.0/H*1.0;    //利用几何关系计算出高度为h处圆杯的半径
11     return PI*h*(rtop*rtop+r*r+rtop*r)/3;   //利用公式计算出该高度下水的体积
12 }
13
14 int main(){
15     int T;scanf("%d",&T);
16     while(T--){
17         scanf("%lf%lf%lf%lf",&r,&R,&H,&v);
18         double l=0,r=H;
19         while(r-l>eps){
20             double mid=(l+r)/2;     //二分答案,枚举水杯中水的高度
21             if(vol(mid)>v)r=mid;
22             else l=mid;
23         }
24         printf("%.6lf\n",l);
25     }
26     return 0;
27 }

2018-11-02

原文地址:https://www.cnblogs.com/00isok/p/9899052.html

时间: 2024-10-09 23:33:04

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【高精度,二分】

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 th

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 1045 二分匹配

题目链接 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6282    Accepted Submission(s): 3551 Problem Description Suppose that we have a square city with straight streets. A map of a city i

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

HDU 4768 Flyer (二分)

OJ题目:click here~~ 题目分析:n个[a  b] 区间,对于i 属于[a  b]  ,从a开始,间隔c ,即i = a , i = a + c , i = a + 2*c -- 将x[ i ] 加1 ,x[ i ] 初值为0 . 已知最多只有一个x[ i ] 为奇数.找到这个i , 和这个奇数. 由于最多只有一个奇数,且奇数 + 偶数 = 奇数.用二分夹逼出这个奇数的位置.找到这个位置,再计算这个奇数就很容易了. AC_CODE const int maxn = 20002; LL

hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1110    Accepted Submission(s): 280 Problem Description Terrorists put some mines in a crowded square recently. The police evacuate all peo

hdu 2962 Trucking (二分+最短路Spfa)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1763    Accepted Submission(s): 618 Problem Description A certain local trucking co