您的位置:首页 > 其它

POJ 3737(UmBasketella)

2018-03-10 13:54 246 查看
In recent days, people always design new things with multifunction. For instance, you can not only use cell phone to call your friends, but you can also use your cell phone take photographs or listen to MP3. Another example is the combination between watch and television. These kinds of multifunction items can always improve people's daily life and are extremely favored by users. The company Mr. Umbrella invented a new kind umbrella "UmBasketella" for people in Rainbow city recently and its idea also comes from such multifunction--the combination of umbrella and daily necessities. This kind of umbrella can be used as a basket and you can put something you want to carry in it. Since Rainbow city rains very often, such innovative usage is successful and "UmBasketella" sells very well. Unfortunately, the original "UmBasketella" do not have an automatic volume control technology so that it is easily damaged when users try to put too many things in it. To solve this problem, you are needed to design an "UmBasketella" with maximum volume. Suppose that "UmBasketella" is a cone-shape container and its surface area (include the bottom) is known, could you find the maximum value of the cone? Input Input contains several test cases. Eash case contains only one real number S, representing the surface area of the cone. It is guaranteed that 1≤S≤10000. Output For each test case, output should contain three lines.
The first line should have a real number representing the maximum volume of the cone.
Output the height of the cone on the second line and the radius of the bottom area of the cone on the third line.
All real numbers should rounded to 0.01. Sample Input
30
Sample Output
10.93
4.37
1.55


可推公式V=1/3*sqrt(-2*S*PI*(r*r-S/(4*PI))^2+S*S*S/(8*PI))

所以V最大值为1/3*sqrt(S*S*S/(8*PI))r最大值为sqrt(S/(4*PI))

h最大值为3*V/(PI*r*r)
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define LL long long
#define maxn 100002
#define PI acos(-1.0)
#define eps 1e-8
using namespace std;
int main()
{
//ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
double S;
while(cin>>S)
{
double r=sqrt(S/4/PI);
double V=S*sqrt(S/(8*PI))/3;
double h=3*V/PI/r/r;
printf("%.2f\n%.2f\n%.2f\n",V,h,r);
/*cout<<V<<endl;
cout<<h<<endl;
cout<<r<<endl;*/
}
return 0;
}
/*
5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0
*/

还有第二种方法 三分!刚学三分 就直接上代码了!#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define LL long long
#define maxn 100002
#define PI acos(-1.0)
#define eps 1e-8
using namespace std;
double S;
double f(double r)
{
return sqrt(-2*S*PI*(r*r-S/4/PI)*(r*r-S/4/PI)+S*S*S/8/PI)/3;
}
int main()
{
//ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
while(cin>>S)
{
/*double r=sqrt(S/4/PI);
double V=S*sqrt(S/(8*PI))/3;
double h=3*V/PI/r/r;*/
double L=0,R=sqrt(S/PI),mid1,mid2;
while(R-L>=eps)
{
mid1=(L*2+R)/3;
mid2=(R*2+L)/3;
if(f(mid2)>f(mid1))
L=mid1;
else
R=mid2;
}
double V=f(L);
double r=L;
double h=3*V/PI/r/r;
printf("%.2f\n%.2f\n%.2f\n",V,h,r);
}
return 0;
}
/*
5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM