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. Atom打造轻量化C/C++ IDE

    写在前面 近期沉迷Atom的颜值无法自拔,在github的光环下,Atom凭借自身良好的素质,获得了大量开发者的青睐.随之而来的就是丰富的插件库,在插件帮助下,它对各种编程语言都有相当好的支持.对与一 ...

  2. Drupal7强制把主题恢复到默认主题

    今天在写Theme,退出登陆的时候无法进入管理后台. 万不得已之下只有使用数据库进行恢复. Rest Drupal Theme to Bartik SQL语句如下: WHERE type = 'the ...

  3. Bootstrap 弹出框(Popover)插件

    Bootstrap 弹出框(Popover)插件与Bootstrap 提示工具(Tooltip)插件类似,提供了一个扩展的视图,用户只需要把鼠标指针悬停到元素上面即可.弹出框的内容完全由Bootstr ...

  4. 《JavaScript入门篇》摘要

    0.课程链接 http://www.imooc.com/learn/36 1.在HTML中加入JS的方法 <script type="text/javascript"> ...

  5. SummerVocation_Learning--java的多线程实现

    java的线程是通过java.lang.Thread类来实现的. 可以通过创建Thread的实例来创建新的线程. 每个线程都是通过某个特定Thread对象所对应的方法run()来完成操作,方法run( ...

  6. [mysql] Can't read from messagefile

    系统:windows 重启mysql服务出现 Server] Can't read from messagefile 等错误时候, 应先执行 mysqld --initialize-insecure ...

  7. pycharm clion rider 注册

    JetBrains 公司出品的pycharm clion rider 专业版本都需要注册才能运行,这里有个免费注册方法: JetBrains授权服务器2017.10.7授权方法:激活时选择Licens ...

  8. k8s的service简述

    k8s向集群外部暴露端口的3种方式: 1.service->nodePort :仅暴露一个宿主机端口,用于集群外部访问,因为此操作被写入各个节点的iptables或ipvs规则当中,可以用任意一 ...

  9. ECMAScript 6入门扩展笔记

    字符串扩展 Unicode相关补充 引入"\u{xx}"来表示码点,之前只能表示\u0000-\uffff引入String.fromCodePoint()能正确读取大于uFFFF的 ...

  10. Python知识点进阶——迭代器

    可迭代对象 可迭代对象可以简单的理解为用for循环遍历的,如list.tuple.dict.set.str 判断一个对象是否是迭代器: 可以将数据类型 和 是否为可迭代对象 比较来判断是否是可以迭代 ...