POJ 3737 UmBasketella 三分法 入门题
来源:互联网 发布:vc高级编程 编辑:程序博客网 时间:2024/06/06 08:53
二分法:适用于单调函数,单调增或单调减
三分法:适用于单峰凸性函数,如二次函数
缩写 l:left ,r: right , m1:mid 1,m2:mid2
三分法模板:
#define eps 10e-6double cal(){}//计算题目所需要的值while(l+eps<r){ m1=l+(r-l)/3; m2=r-(r-l)/3; v1=cal(m1); v2=cal(m2); if(v1<v2)l=m1; else r=m2;}
AC代码:
View Code
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#define eps 10e-6using namespace std;const double pi = acos(double(-1));double S;double cal(double r){ double R = S/pi/r-r; double h = sqrt(R*R-r*r); return h*pi*r*r/3;}int main(){ while(~scanf("%lf",&S)) { double l= 0,r= sqrt(S/pi); double m1,m2,v1,v2; while(l+eps<r) { m1=l+(r-l)/3; m2=r-(r-l)/3; v1=cal(m1); v2=cal(m2); if(v1<v2)l=m1; else r=m2; } double R = S/pi/r-r; double h = sqrt(R*R-r*r); double V = h*pi*r*r/3; printf("%.2f\n%.2f\n%.2f\n",V,h,r); }}
- 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(三分)
- day5 POJ 3737 UmBasketella
- poj-3737(UmBasketella)
- POJ 3737 UmBasketella
- [POJ 3737][三分]UmBasketella
- [POJ3737]UmBasketella(三分法)
- POJ 3737 UmBasketella(三分)
- poj 3737 UmBasketella(三分+求导)
- POJ 3737 UmBasketella (数学)
- POJ 3737 UmBasketella(三分)
- HDU 1421 搬寝室 类似背包DP
- HDU 1024 Max Sum Plus Plus 经典 DP
- POJ 2955 Brackets 区间DP 入门题
- Unity3D 200个插件免费分享
- POJ 1976 A Mini Locomotive DP
- POJ 3737 UmBasketella 三分法 入门题
- POJ 3628 Bookshelf 2 0-1背包 or DFS 水题
- 约瑟夫环的解决
- POJ 1948 Triangular Pastures 二维 0-1背包
- HDU 3033 I love sneakers! 分组背包+约束限制(每组至少取一个)。
- HDU 3535 AreYouBusy 经典混合背包
- POJ 1252 Euro Efficiency 2个完全背包
- POJ 2063 Investment 完全背包
- POJ3260 The Fewest Coins 多重背包+完全背包