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;
    return pai*temp*(r1*r1+rr*rr+r1*rr)/3;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf",&r1,&r2,&h,&v);
        double i;
        for(i=0;i<100;i+=0.0001)
        {
            if(get_v(i)>v)
                break;
        }
        double j;
        for(j=i-0.0001;j<=i;j+=0.00000001)
        {
            if(get_v(j)>v)
                break;
        }
        printf("%.6lf\n",j);
    }
    return 0;
}

虽然时间久了一点,单这道题的数据是可以过得。自己想到方法解决问题,很开心。

下面是迪神一下子就想到的二分解法,说来迪神也真是牛逼……在我们这种菜鸟云集的地方,应该算的上是鹤立鸡群了。。。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define PI acos(-1.0)
double r,R,H,v,m,x,y;
int L()
{
    if((PI * m * (r*r + r*((R-r)/H*m+r) + ((R-r)/H*m+r)*((R-r)/H*m+r))/3-v)>1e-7) return 1;
    else return 0;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>r>>R>>H>>v;
        x=0,y=H;
        while((y-x)>1e-7)
        {
            m=x+(y-x)/2;
            if(L()) y=m;
            else x=m;
        }
        printf("%.6lf\n",x);
    }
}

就是这个样子,打电话久了会困……原来是真的。。。

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

时间: 2024-11-17 18:58:37

HDU 2289 Cup(二分可以,但是除了二分呢?)的相关文章

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【二分】

<题目链接> 题目大意: 一个圆台型的杯子,它的上底半径和下底半径已经给出,并且给出它的高度,问你,体积为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

hdu 5030 Rabbit&#39;s String(后缀数组&amp;二分)

Rabbit's String Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 288    Accepted Submission(s): 108 Problem Description Long long ago, there lived a lot of rabbits in the forest. One day, the

HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)

题目地址:HDU 1839 我去..原来这题这么简单...网络流中这种二分建图的方式做了一大堆了..这种题还能难倒我吗...白天一直没怎么看懂题,对题意懵懵懂懂的...晚上好好看了看题,这不就是网络流中练的最多的那种二分建图模型吗....只是把网络流算法改成最短路就行了..但是两个地方手残了没能在实验室当场A掉..sad... 这题就是二分最小容量,对满足容量的加边,对时间求最短路.如果最短时间比规定时间少的话就可以继续增加容量,直到不能增加为止. 代码如下: #include <iostrea

HDU 2063:过山车(二分匹配,匈牙利算法)

过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9745    Accepted Submission(s): 4294 Problem Description RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做par

hdu 4004 The Frog&#39;s Games【二分】

The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3980    Accepted Submission(s): 1931 Problem Description The annual Games in frogs' kingdom started again. The most famous game

HDU 3729 I&#39;m Telling the Truth (二分匹配)

题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹配,裸的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #inc

hdu 4004 The Frog&#39;s Games 【二分】

The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 4565    Accepted Submission(s): 2225 Problem Description The annual Games in frogs' kingdom started again. The most famous game