三分 HDOJ 3714 Error Curves

题目传送门

 1 /*
 2     三分:凹(凸)函数求极值
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstring>
 7 #include <cmath>
 8 using namespace std;
 9
10 const int MAXN = 1e4 + 10;
11 const int INF = 0x3f3f3f3f;
12 const double EPS = 0.0000000001;
13 struct F    {
14     double a, b, c;
15 }f[MAXN];
16 int n;
17
18 double cal(double x)    {
19     double res = -INF;
20     for (int i=1; i<=n; ++i)    {
21         res = max (res, f[i].a * x * x + f[i].b * x + f[i].c);
22     }
23     return res;
24 }
25
26 int main(void)  {       //HDOJ 3714 Error Curves
27     //freopen ("HDOJ_3714.in", "r", stdin);
28
29     int T;  scanf ("%d", &T);
30     while (T--) {
31         scanf ("%d", &n);
32         for (int i=1; i<=n; ++i)    {
33             scanf ("%lf%lf%lf", &f[i].a, &f[i].b, &f[i].c);
34         }
35
36         double l = 0.0, r = 1000.0;
37         for (int i=1; i<=100; ++i)  {
38             double mid = (l + r) / 2;
39             double rmid = (mid + r) / 2;
40             if (cal (mid) < cal (rmid)) r = rmid;
41             else    l = mid;
42         }
43         printf ("%.4f\n", cal (r));
44     }
45
46     return 0;
47 }
时间: 2024-10-11 11:45:32

三分 HDOJ 3714 Error Curves的相关文章

HDU 3714 Error Curves

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4536    Accepted Submission(s): 1721 Problem Description Josephina is a clever g

LA 5009 (HDU 3714) Error Curves (三分)

A - Error Curves Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPracticeUVALive 5009 Appoint description: Description Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a

hdu 3714 Error Curves(三分)

Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1198    Accepted Submission(s): 460 Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pa

HDU 3714 Error Curves(3分)

题意  求分段函数的最低点  每个点函数值为n个 a*x^2 + b*x +c (a>=0, |b|<5000, |c|<5000) 函数的最大值 由于a是不小于0的   所以此分段函数的函数图像只可能是类似'V'形的  可以画图观察出来  那么求最小值就可以用三分来解决了 #include <bits/stdc++.h> using namespace std; const int N = 10005; const double eps = 1e-9; int a[N],

UVA - 1476 Error Curves 三分

                                       Error Curves Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties.In order to test

UVALive 5009 Error Curves 三分

//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits

UVA - 1476 Error Curves (三分搜索)

Description Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties. In order to test the algorithm's efficiency, she collect

HDU3714——三分——Error Curves

Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties. In order to test the algorithm's efficiency, she collects many datas

Error Curves HDU - 3714

Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties. In order to test the algorithm's efficiency, she collects many datas