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

hdu_2289:Cup

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

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

题解:这是一道经典的二分的题,要注意在二分的时候对精度的判断和对特殊情况的考虑比如水溢出的情况。在推算公式的时候也要注意分母上的数不要有可能等于0 ,这就要求用更加合理的方法推算公式,这个题就是要用倾斜角来算比较好,这样分母上就是H不可能等于0;

代码:

 #include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define PI acos(-1)
#define eps 1e-8
double r , R , H , rr ,v,vv;
double f(double h)
{
return h*(R-r)/H+r;
}
double g(double rr,double h)
{
return (1.0/)*h*PI*(rr*rr+r*r+rr*r);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf %lf %lf %lf",&r,&R,&H,&v);
double tm = 1.0/*PI*H*(R*R+r*r+R*r);
double left= , right=H , mid = H/ ,vv = g(f(mid),mid);
if(tm<=v){
printf("%.6lf\n",H);
continue;//注意是continue还是break,因为这个哇了
}
else{
while(fabs(vv-v) > eps){
if(vv>v)
right = mid;
else
left = mid ;
mid = (left+right)/;
vv = g(f(mid),mid);
}
printf("%.6lf\n",mid);
}
}
return ;
}

Cup(二分)的更多相关文章

  1. HDU 2289 CUP 二分

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  2. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  3. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)

    A. Is it rated? time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...

  4. HDU 2289 Cup【高精度,二分】

    Cup Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心

    A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. 二分(HDU2289 Cup)

    贴代码: 题目意思:已知r水的下半径,R水的上半径,H为圆台高度,V为水的体积,求水的高度,如图: 水的高度一定在0-100,所以在这个区间逐步二分,对每次二分出的水的高度,计算相应的体积,看看计算出 ...

  7. HDU 2289 Cup【二分】

    <题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为V的水倒入这个杯子中,高度为多少. 解题分析: 就是简单的二分答案,二分枚举杯中水 ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  9. 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

    题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...

随机推荐

  1. bzoj 2752: [HAOI2012]高速公路(road)

    Description Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站.Y901高速公路是一条由N-1段路以及N个收 ...

  2. Zabbix自动发现监控Tomcat进程

    1.编辑自动发现脚本 自动发现脚本只支持JSON格式 #!/usr/bin/env python # -*- coding:utf-8 -*- import commands import psuti ...

  3. Struts2-整理笔记(五)拦截器、拦截器配置

    拦截器(Interceptor) 拦截器是Struts2最强大的特性之一,它是一种可以让用户在Action执行之前和Result执行之后进行一些功能处理的机制. 拦截器的优点 简化了Action的实现 ...

  4. Rstudio( bioconductor)下载太慢,用国内镜像

    在Rstudio中,下载软件install.packages()和 bioconductor软件下载命令 source("http://bioconductor.org/biocLite.R ...

  5. 前端生成验证码图片utils

    <%@ page language="java" contentType="text/html; charset=UTF-8"     pageEncod ...

  6. NET控件Designer架构设计

    总体结构 Designer总体上由三大部分组成:View,ViewModel和Model,这个结构借鉴了流行的MVVM模式.这三部分的职责分工是: View 负责把ViewModel以图形的方式展现出 ...

  7. XUL透明异形旋转窗体

    200行不到的代码,实现透明异形旋转窗体. 下载(25MB): http://oltag.com:8080/yaolixing/18/11/00/OHUIv52.0.1_3_webTrans20180 ...

  8. Fiddler的script用法

    一.关于Fiddler Script Fiddler Script 是用JScript.NET语言写的.Fiddler 包含了一个脚本文件可以自动修改Http Request 和Response.这样 ...

  9. [js高手之路]面向对象版本匀速运动框架

    这篇文章的效果,需要看过以下3篇文章: [js插件开发教程]一步步开发一个可以定制配置的隔行变色小插件 [js高手之路]匀速运动与实例实战(侧边栏,淡入淡出) [js高手之路]打造通用的匀速运动框架 ...

  10. Java的注释和Javadoc在eclipse生成的方法 – Break易站

    本文内容来自:Java的注释和Javadoc在eclipse生成的方法 – Break易站 1.  Java的注释 Java里有两种注释风格.下面这个写法是非常常见的 1 2 3 4 /*This i ...