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位小数才能保证精度不受损失
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. int n;
  7. struct node{
  8. double a,b,c;
  9. }que[];
  10. double esp=1e-;
  11. double ff(double x){
  12. double tmax=que[].a*x*x+que[].b*x+que[].c;
  13. for(int i=;i<n;i++){
  14. tmax=max(tmax,que[i].a*x*x+que[i].b*x+que[i].c);
  15. }
  16. return tmax;
  17. }
  18.  
  19. void calculate(){
  20. double l=,r=1000.0;
  21. double ans1,ans2;
  22. while(l+esp<r){
  23. double mid=(l+r)/2.0;
  24. double midmid=(mid+r)/2.0;
  25. ans1=ff(mid);
  26. ans2=ff(midmid);
  27. if(ans1<ans2){
  28. r=midmid;
  29. }
  30. else
  31. l=mid;
  32.  
  33. }
  34. printf("%.4lf\n",ans1);
  35. }
  36.  
  37. int main(){
  38. int t;
  39. scanf("%d",&t);
  40. while(t--){
  41. memset(que,,sizeof(que));
  42. scanf("%d",&n);
  43. for(int i=;i<n;i++){
  44. scanf("%lf%lf%lf",&que[i].a,&que[i].b,&que[i].c);
  45.  
  46. }
  47. calculate();
  48. }
  49. return ;
  50. }

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. js 正则匹配(去掉html标签)

    正则匹配去掉所有html标签 var a = "<span>999</span>" a = a.replace(/<[^>]+>/g,' ...

  2. httpd2.4.6三种工作模式(如何配置),防止占用内存暴增的策略

    之前偷懒默认用yum安装了httpd.后来发现服务器内存暴增,一度达到75% 打开一看,好嘛后台休眠进程全是httpd. 重启之后再度访问发现内存还是稳步增长. [root@iz2ze3ayxs2yp ...

  3. RHEL7 本地yum源配置

    配置yum 源 1.挂载DVD光盘到/mnt   因为配置时候路径名里面不能有空格,否则不能识别  [root@ mnt]# mount /dev/cdrom /mnt 2.在目录/etc/yum.r ...

  4. Ribbon 负载均衡搭建

    本机IP为  192.168.1.102 1.   新建Maven  项目    ribbon 2.   pom.xml <project xmlns="http://maven.ap ...

  5. C# checked运算符

    一.C# checked运算符 checked运算符用于对整型算术运算和显式转换启用溢出检查. 默认情况下,表达式产生的值如果超出了目标类型的范围,将会产生两种情况: ?常数表达式将导致编译时错误. ...

  6. React后台管理系统-file-uploader组件

    1.React文件上传组件github地址: https://github.com/SoAanyip/React-FileUpload 2.Util里边新建file-uploader文件夹,里边新建i ...

  7. vmware:使用.zip文件在vmware中安装操作系统

    问题描述: 之前在vmware中安装系统时,全部都是加载的.iso文件来实现.后面同事给了一个zip包,解压后是".vmdk"等一系列具体的文件.一时间不知道怎么安装系统了,搜网页 ...

  8. https及其背后的加密原理阅读总结

    https是以安全为目标的http通道,简单讲是http的安全版.当我们往服务器发送比较隐私的数据(比如说你的银行卡,身份证)时,如果使用http进行通信.那么安全性将得不到保障. 首先数据在传输的过 ...

  9. 设计模式基础--Java接口和抽象类

    最近在看设计模式,感觉需要先好好区分下抽象类和接口. 一.抽象类 <Java编程思想>中这样定义:包含抽象方法的类叫做抽象类. 解释: 1.包含,说明抽象类中可以有其他的具体方法. 2.因 ...

  10. centos7上mysql8.0rpm方式安装

    首先是下载图解 1.首先卸载centos7中自带的mariadb rpm -qa|grep mariadb //查询出来已安装的mariadb rpm -e --nodeps 文件名 //卸载mari ...