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
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
2
1
2 0 0
2
2 0 0
2 -4 2
 
Sample Output
0.0000
0.5000
 
Author
LIN, Yue
 
Source
 
Recommend
zhouzeyong
 
 
该题欲求众多二次函数中当x为0-1000之间的每个值的时候函数最大值,
将所有最大值求出输出最小的一个便可以,
解决方法:三分,
中间更新区间的时候调换一下位置即可,因为本体求得是最小值
 
ps:esp取1e-8的时候过不去,为WA,当开到1e-9的时候就过去了,原因可能是本题答案要求输出4位小数点,而在计算二次函数的时候计算了x*x会生成8位小数,所有保留9位小数才能保证精度不受损失
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct node{
double a,b,c;
}que[];
double esp=1e-;
double ff(double x){
double tmax=que[].a*x*x+que[].b*x+que[].c;
for(int i=;i<n;i++){
tmax=max(tmax,que[i].a*x*x+que[i].b*x+que[i].c);
}
return tmax;
} void calculate(){
double l=,r=1000.0;
double ans1,ans2;
while(l+esp<r){
double mid=(l+r)/2.0;
double midmid=(mid+r)/2.0;
ans1=ff(mid);
ans2=ff(midmid);
if(ans1<ans2){
r=midmid;
}
else
l=mid; }
printf("%.4lf\n",ans1);
} int main(){
int t;
scanf("%d",&t);
while(t--){
memset(que,,sizeof(que));
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf%lf",&que[i].a,&que[i].b,&que[i].c); }
calculate();
}
return ;
}

hdu 3714 Error Curves(三分)的更多相关文章

  1. nyoj 1029/hdu 3714 Error Curves 三分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3714 懂了三分思想和F(x)函数的单调性质,这题也就是水题了 #include "stdio ...

  2. hdu 3714 Error Curves(三分)

    http://acm.hdu.edu.cn/showproblem.php?pid=3714 [题意]: 题目意思看了很久很久,简单地说就是给你n个二次函数,定义域为[0,1000], 求x在定义域中 ...

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

    Error Curves Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPr ...

  4. HDU 3714 Error Curves

    Error Curves 思路:这个题的思路和上一个题的思路一样,但是这个题目卡精度,要在计算时,卡到1e-9. #include<cstdio> #include<cstring& ...

  5. 三分 HDOJ 3714 Error Curves

    题目传送门 /* 三分:凹(凸)函数求极值 */ #include <cstdio> #include <algorithm> #include <cstring> ...

  6. UVA - 1476 Error Curves 三分

                                           Error Curves Josephina is a clever girl and addicted to Machi ...

  7. UVALive 5009 Error Curves 三分

    //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include& ...

  8. Error Curves HDU - 3714

    Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...

  9. HDU 3714/UVA1476 Error Curves

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

随机推荐

  1. Java的内存回收机制详解X

    http://blog.csdn.net/yqlakers/article/details/70138786 1 垃圾回收的意义 在C++中,对象所占的内存在程序结束运行之前一直被占用,在明确释放之前 ...

  2. 2017.12.11 String 类中常用的方法

    1.编写程序将 "jdk" 全部变为大写,并输出到屏幕,截取子串"DK" 并输出到屏幕 package demo; import java.util.Scann ...

  3. cloudera manager的卸载以及重新安装

    1 卸载cloudera 参照 http://www.cnblogs.com/chenfool/p/3738540.html Cloudera 的官方介绍: http://www.cloudera.c ...

  4. MAC之tar解压与压缩gz打包命令

    tar [-cxtzjvfpPN] 文件与目录 ....参数:-c :建立一个压缩文件的参数指令(create 的意思):-x :解开一个压缩文件的参数指令!-t :查看 tarfile 里面的文件! ...

  5. js实现全选,反选,全不选

    思路:1.获取元素.2.用for循环历遍数组,把checkbox的checked设置为true即实现全选,把checkbox的checked设置为false即实现不选.3.通过if判断,如果check ...

  6. java基础面试题:java中有没有goto? 在JAVA中如何跳出当前的多重嵌套循环?

    goto是Java的保留关键字,但是从来没有直接使用到goto,goto的跳转作用在Java中受到了限制,只有在特定场合下才能使用,如while for等循环中用continue.break或结合标签 ...

  7. es6中的promise解读

    目录 什么是promise? promise的优点 回调地狱问题  Promise的三种状态 一个简单的promise promise中的then 利用promise解决回调地狱 promise的链式 ...

  8. SpringSecurity项目报错

    启动时,提示: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory be ...

  9. MVP模式与MVVM模式

    1.mvp模式(Model层 Presenter层 View 层) Model层 :数据层(ajax请求) Presenter层:呈现层,view逻辑相关的控制层,控制层可以去调Model去发ajax ...

  10. 使用natapp本地映射外网服务

    官网:https://natapp.cn/ 软件很好用,这对于前端工程师来说,有了这个工具就很爽了,当你的领导或者不在你公司内网范围内的人,想要看你的页面效果,就很简单了. 详细的不用更多介绍,直接去 ...