UVALive 5009
2016-03-22 19:42
411 查看
Link:click here
The question:给出n组a,b,c的值,求出函数值最大值的最小值
Solution:三分,黄金分割法(优选法),Fibonacci搜索都可求单峰函数的极值。
Conclusion:跟据题目要求判断循环的次数或者需要控制的精度 Code:
The question:给出n组a,b,c的值,求出函数值最大值的最小值
Solution:三分,黄金分割法(优选法),Fibonacci搜索都可求单峰函数的极值。
Conclusion:跟据题目要求判断循环的次数或者需要控制的精度 Code:
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int n; int a[10004], b[10004], c[10004]; double F(double x) { double ans = a[0] * x * x + b[0] * x + c[0]; for (int i = 1; i < n; i++) { ans = max(ans, a[i] * x * x + b[i] * x + c[i]); } return ans; } int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d%d", &a[i], &b[i], &c[i]); } double L = 0.0, R = 1000.0; double m1, m2; while (R - L > eps) { m1 = L + (R - L) / 3.0; m2 = R - (R - L) / 3.0; if (F(m1) < F(m2)) R = m2; else L = m1; } printf("%.4f\n", F(L)); } return 0; }
相关文章推荐
- HDU4355--Party All the Time,HDU3714--Error Curvese三分法
- CSU 1548 Road And Bridge acm 三分
- HDU 4717 The Moving Points
- [HDU4355][三分]Party All The Time
- cf#320 Div.2 Problem E Weakness and Poorness
- HDU 2438 Turn the corner
- 三分之hihocoder1142
- 三分之ZOJ3203
- 三分之HDU3714
- Trick or Treat
- HDU 2438 Turn the corner(三分)
- 【SDOI2013】【BZOJ3203】保护出题人
- BZOJ1038 瞭望塔
- hdu 3714
- URAL 1874 Football Goal 均值不等式&三分
- 【算法分析】之重新认识三分-----求极值(极大值和极小值)
- poj3737UmBasketella三分法求极值
- ZOJ 3203 Light Bulb (三分+计算几何)
- 题目3 : 活动中心
- HDOJ 4355 —— 三分