HDOJ Error Curves 计算几何
2012-03-31 20:28
330 查看
题意:在给定的n个抛物线中,求 min(F(x)), F(x) = max(S(x)).
思路:由于给定的抛物线都是开口向上的(0 ≤ a ≤ 100)F(x)也是开口向上的类抛物线,具有单峰值,利用三分求解 。
思路:由于给定的抛物线都是开口向上的(0 ≤ a ≤ 100)F(x)也是开口向上的类抛物线,具有单峰值,利用三分求解 。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define eps 1e-10 const int MAX = 10009; struct para { int a, b, c; }; para p[MAX]; int n; double getmax(double x) { double ans, tmp; ans = p[0].a*x*x + p[0].b*x + p[0].c; int i; for (i = 1; i < n; ++i) { tmp = p[i].a*x*x + p[i].b*x + p[i].c; if (ans < tmp) ans = tmp; } return ans; } int main() { int t; double l, r, mid1, mid2, max1, max2; scanf("%d",&t); while (t--) { scanf("%d", &n); int i; for (i = 0; i < n; ++i) scanf("%d %d %d", &p[i].a, &p[i].b, &p[i].c); l = 0.0; r = 1000.0; while (fabs(r-l) > eps) { mid1 = (l+r)/2; mid2 = (l+mid1)/2; max1 = getmax(mid1); max2 = getmax(mid2); if (max1 > max2) r = mid1; else l = mid2; } printf("%.4lf\n", max1); } return 0; }
相关文章推荐
- hdoj 2036 (计算几何,叉积求面积)
- HDOJ1221 计算几何入门题
- 【计算几何】 HDOJ 4998 Rotate
- hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)
- hdoj 4946 计算几何求凸包
- HDOJ 4454 Stealing a Cake 计算几何
- hdoj 2436 Collision Detection(数学型计算几何)
- hdoj4643GSM【计算几何+二分思想】
- 【集训笔记】计算几何【HDOJ2036【HDOJ1086【HDOJ1115【HDOJ1147【HDOJ1392 【ZOJ2976
- HDOJ/HDU 2438 计算几何+三分
- [HDOJ 3432][BNUOJ 7543] Wax [计算几何+二分答案]
- hdoj Intersection 5120 (数学计算几何) 求两个相交圆的面积
- [HDOJ 4892] Defence of the Trees [计算几何+最短路+状态压缩]
- 计算几何 凸包 hdoj2108 Shape of HDU
- hdoj.4404 Worms【计算几何+圆与多边形相交面积】 2015/08/17
- 【计算几何】 HDOJ 5017 Ellipsoid
- (精)hdoj2108(计算几何)(判断凸多边形)
- 【HDOJ5538】House Building(计算几何)