UmBasketella(三分算法解决单峰问题)
来源:互联网 发布:网络作家笔名 编辑:程序博客网 时间:2024/05/16 03:28
Question
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.
Simple Input
30
Simple Output
10.93
4.37
1.55
Code 1
#include <iostream>#include <algorithm>#include <cmath>#include <stdio.h>using namespace std;double pi=acos(-1.0);double S;double height(double r);double valume(double r);int main(){ int i,j,k; double l,r,mid1,mid2; while(cin>>S) { l=0;r=sqrt(S/(pi*2));//尽量缩小l和r的范围,不可写成sqrt(S/pi)。 while(l+0.0001<r) { mid1=(r+l)/2.0; mid2=(mid1+r)/2.0; if(valume(mid1)>valume(mid2)) r=mid2; else l=mid1; } printf("%.2lf\n",valume(l)); printf("%.2lf\n",height(l)); printf("%.2lf\n",l); } return 0;}double height(double r){ double R; R=(S-pi*r*r)/(pi*r); return sqrt(R*R-r*r);}double valume(double r){ double h; h=height(r); return pi*r*r*h/3.0;}
Code 2
#include <iostream>#include <cmath>#include <stdio.h>using namespace std;double PI=acos(-1.0);int main(){ double s,h,r,v; while(cin>>s) { r=sqrt(s/PI)/2.0; h=sqrt((s*s)/(PI*PI*r*r)-2.0*s/PI); v=PI*r*r*h/3.0; printf("%.2lf\n%.2lf\n%.2lf\n",v,h,r); } return 0;}
说明:圆锥体面积:S=PI*L*R+PI*R*R;L=sqrt(h*h+R*R);
既有R*R=S*S/(PI*PI*h*h+2*PI*S);
V=PI*R*R*h/3;将R*R带入求导函数零点即为最大值点;即可求出h,r,v
- UmBasketella(三分算法解决单峰问题)
- POJ 3737 UmBasketella (三分算法)
- POJ 3737 UmBasketella(三分)
- POJ 3737 UmBasketella(三分)
- POJ - 3737 - UmBasketella(三分)
- POJ 3737 UmBasketella(三分)
- poj 3737 UmBasketella(三分)
- poj 3737 UmBasketella (三分)
- POJ 3737 UmBasketella(三分模板)
- POJ 3737 UmBasketella 三分
- poj 3737 UmBasketella 三分
- [POJ 3737]UmBasketella(三分)
- poj3737 UmBasketella [三分]
- poj3737 UmBasketella(三分)
- [POJ 3737][三分]UmBasketella
- [复习][poj3737]三分 UmBasketella
- 分治算法实验-单峰序列问题
- poj 3737 UmBasketella(三分+求导)
- Java并发同步
- hadoop常用的命令
- [Zabbix] Agent 安装
- stl list原理和用法
- 结构体初始化 initializer element is not constant
- UmBasketella(三分算法解决单峰问题)
- git/gerrit 常用命令记载
- 「とても」「あまり」「大変」的用法区别
- cocos2d-x3.2 24种基本特效
- 本文主要阐述了四种排序方法
- 腾讯开源ncnn:Ubuntu下运行示例
- windows下gem install报certificate verify failed错误解决办法或者添加淘宝源镜像失败
- 设计模式4-模板方法模式
- bugfree安装教程