首页 > ACM题库 > HDU-杭电 > hdu 2493 Timer-分治-[解题报告]C++
2014
02-09

hdu 2493 Timer-分治-[解题报告]C++

Timer

问题描述 :

Recently, some archaeologists discovered an ancient relic on a small island in the Pacific Ocean. In the relic, they found an interesting cone shaped container with transparent bottom. The container lay on the horizontal ground with its central axis parallel to the ground. Just beside the container, they found a manual telling them something about the container.

The container was a timer for a special ceremony. Ancient people filled it all with water before the ceremony, and when the ceremony began, they pulled out the plug in the small hole on the tip of the cone to let the water out. There was a horizontal line called “sacred line” carved on the bottom of the cone, and when the water level hit that line, they pushed the plug back and ended the ceremony. But the archaeologists could not found the sacred line on that cone. In order to sell the timer at a good prize, the archaeologists wanted to recover that very important line.

By the manual they figured out how much water flew out when the ceremony ended, but they don’t know what to do next, so they come to you for help.

They measures the height of the cone, and the diameter of the bottom, you should tell them the sacred line’s height above the ground.

输入:

The first line of the input contains an integer T(1<=T<=20), indicating the number of test cases.

Each line after that is a test case. It contains three real numbers, H, D(1<=H,D<=1000) and V, indicating the height and bottom diameter of the timer, and the volume of water that flew out during the ceremony. That volume is guaranteed to be less than half volume of the container.

输出:

The first line of the input contains an integer T(1<=T<=20), indicating the number of test cases.

Each line after that is a test case. It contains three real numbers, H, D(1<=H,D<=1000) and V, indicating the height and bottom diameter of the timer, and the volume of water that flew out during the ceremony. That volume is guaranteed to be less than half volume of the container.

样例输入:

2
5.0 10.0 0.0
5.0 10.0 65.4498

样例输出:

10.00000
5.00000

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493

题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来水的体积为V,给你地面直径D,高H,让你求小洞里地面的距离。(保证距离大于等于半径,小于等于直径)

题解:因为流出来水的那部分是一个不规则形状(相当于将圆锥水平切开,截面是一个三角形),我们可以二分答案下降高度r,现在关键是求体积。

然后通过一系列很复杂的积分运算,得出结果:

记得最后求出来的答案要用直径减去。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define sd1(a) scanf("%lf",&a)
#define sd2(a,b) scanf("%lf%lf",&a,&b)
#define ss1(s)  scanf("%s",s)
#define pi1(a)    printf("%d\n",a)
#define pi2(a,b)  printf("%d %d\n",a,b)
#define mset(a,b)   memset(a,b,sizeof(a))
#define forb(i,a,b)   for(int i=a;i<b;i++)
#define ford(i,a,b)   for(int i=a;i<=b;i++)

typedef long long LL;
const int N=100005;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;

double H,D,V,R;

double xiaohao(double r)//这个地方求积分很麻烦,我就只写结果了
{
    double xh=0;
    xh+=H*R*R*acos((R-r)/R)/3.0;
    xh-=2.0/3.0*(R-r)*H*sqrt(R*R-(R-r)*(R-r));
    xh+=1.0/3.0*(R-r)*(R-r)*(R-r)*H/R*log((R+sqrt(R*R-(R-r)*(R-r)))/(R-r));
    return xh;
}

int main()
{
//    freopen("input.txt","r",stdin);
    int i,j,T;
    si1(T);
    while(T--)
    {
        sd1(H);sd2(D,V);
        R=D/2;
        double low=0,up=R,m,tmp;
        while((up-low)>eps)//二分高度
        {
            m=(up+low)/2;
            double tmp=xiaohao(m);//求出体积,和V比较
            if(tmp>V)
                up=m;
            else
                low=m;
        }
        printf("%.5f\n",D-m);
    }
    return 0;
}

解题转自:http://blog.csdn.net/xh_reventon/article/details/12199111


  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  2. Thanks for taking the time to examine this, I really feel strongly about it and love studying a lot more on this topic. If possible, as you acquire experience