HDU/HDOJ 3714 Error Curves 2010年成都赛区
来源:互联网 发布:iphone更新后数据丢失 编辑:程序博客网 时间:2024/05/01 08:36
Error Curves
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 300 Accepted Submission(s): 113
Problem 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 collects many datasets.
What's more, each data is divided into two parts: training data and test
data. She gets the parameters of the model on training data and test the
model on test data. To her surprise, she finds each dataset's test error curve is just a parabolic curve. A parabolic curve corresponds to a quadratic function. In mathematics, a quadratic function is a polynomial function of the form f(x) = ax2 + bx + c. The quadratic will degrade to linear function if a = 0.
It's very easy to calculate the minimal error if there is only one test error curve. However, there are several datasets, which means Josephina will obtain many parabolic curves. Josephina wants to get the tuned parameters that make the best performance on all datasets. So she should take all error curves into account, i.e., she has to deal with many quadric functions and make a new error definition to represent the total error. Now, she focuses on the following new function's minimum which related to multiple quadric functions. The new function F(x) is defined as follows: F(x) = max(Si(x)), i = 1...n. The domain of x is [0, 1000]. Si(x) is a quadric function. Josephina wonders the minimum of F(x). Unfortunately, it's too hard for her to solve this problem. As a super programmer, can you help her?
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 datasets.
What's more, each data is divided into two parts: training data and test
data. She gets the parameters of the model on training data and test the
model on test data. To her surprise, she finds each dataset's test error curve is just a parabolic curve. A parabolic curve corresponds to a quadratic function. In mathematics, a quadratic function is a polynomial function of the form f(x) = ax2 + bx + c. The quadratic will degrade to linear function if a = 0.
It's very easy to calculate the minimal error if there is only one test error curve. However, there are several datasets, which means Josephina will obtain many parabolic curves. Josephina wants to get the tuned parameters that make the best performance on all datasets. So she should take all error curves into account, i.e., she has to deal with many quadric functions and make a new error definition to represent the total error. Now, she focuses on the following new function's minimum which related to multiple quadric functions. The new function F(x) is defined as follows: F(x) = max(Si(x)), i = 1...n. The domain of x is [0, 1000]. Si(x) is a quadric function. Josephina wonders the minimum of F(x). Unfortunately, it's too hard for her to solve this problem. As a super programmer, can you help her?
Input
The input contains multiple test cases. The first line is the number of cases T (T < 100). Each case begins with a number n (n ≤ 10000). Following n lines, each line contains three integers a (0 ≤ a ≤ 100), b (|b| ≤ 5000), c (|c| ≤ 5000), which mean the corresponding coefficients of a quadratic function.
Output
For each test case, output the answer in a line. Round to 4 digits after the decimal point.
Sample Input
212 0 022 0 02 -4 2
Sample Output
0.00000.5000
Author
LIN, Yue
Source
The 2010 ACM-ICPC Asia Chengdu Regional Contest
Recommend
zhouzeyong
我的思路:
可以简单的画一下图发现,几个抛物线取最大的图像只能是一个单峰的函数
而且仅仅只有一个最小值。
画下图能够充分的理解这一点。
然后知道这个函数是单峰的就很好了,我们可以直接三分。把这个最小值给计算出来。
做的时候注意,此题每个函数的最小值可能会小于0。
所以定义的最大值在初始化的时候不能简单的认为就是0了,而要搞成负无穷这里//我WA到si才反应过来的
我的代码:
#include<stdio.h>#include<algorithm>#include<math.h>struct node{ double a; double b; double c;};node fun[10005];double max(double a,double b){ if(a>b) return a; else return b;}double f(int i,double x){ return fun[i].a*x*x+fun[i].b*x+fun[i].c;}double cal(double x,int n){ int i; double h=-99999999; for(i=1;i<=n;i++) h=max(h,f(i,x)); return h;}void solve(int n){int i; double left,right,mid1,mid2,h1,h2; left=0,right=1000.0; for(i=1;i<=100;i++) { mid1=(2*left+right)/3; mid2=(left+2*right)/3; h1=cal(mid1,n); h2=cal(mid2,n); if(h1>h2) { left=mid1; } else { right=mid2; } } double ans=cal(left,n); printf("%.4lf\n",ans);}int main(){ int i,n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%lf%lf%lf",&fun[i].a,&fun[i].b,&fun[i].c); solve(n); } return 0;}
- HDU/HDOJ 3714 Error Curves 2010年成都赛区
- hdu 3714 Error Curves 2010年成都赛区
- HDOJ/HDU 3715 2-sat+二分 2010年成都赛区
- hdu 3714 Error Curves
- HDU 3714 Error Curves
- hdu 3714 Error Curves
- hdu 3714 Error Curves
- HDU 3714 Error Curves.
- HDU 3714 Error Curves
- HDU 3714 Error Curves
- HDU 3714 Error Curves
- hdu 3714 Error Curves
- HDU-3714 Error Curves
- HDU 3714 Error Curves
- [三分]HDOJ 3714Error Curves
- hdu 3714 Error Curves (三分)
- 2012年成都赛区小结
- HDOJ 3714 Error Curves 三分搜索
- iphone开发中文章显示的一种排版技术
- 纠结啊!!!!!!!!!!!!!!!到底java还是.net???
- C#程序退出的几种方法及说明
- Android SD卡操作 (Environment 状态)
- 编写pl/sql包并执行包中的过程和函数
- HDU/HDOJ 3714 Error Curves 2010年成都赛区
- 手把手教你把Vim改装成一个IDE编程环境(图文)
- ubuntu 内核编译
- CATransition的动画效果类型及实现方法
- C#编译器
- C++ 学习--------------公有MI 与 虚基类
- C#百科的抓取源代码
- CGI ASP JSP PHP
- 2009年工作总结