Error Curves(2010成都现场赛题)
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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 ifa = 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 minimal which related to multiple quadric functions.
The new function F(x) is defined as follow:
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
简单三分。
可以证明,许多二次函数f取其最大即F(x)=max(f(x))依然为下凸函数,类似二次函数。
便可进行三分处理。
#include<cmath>
#include<iostream>
#include<cstdio>
#define max(x,y) ((x)<(y)?(y):(x))
double l,r,a[],b[],c[],mid,mmid;
int n;
double f(double x){
double ans=-;
for(int i=;i<=n;i++)
ans=max(ans,a[i]*x*x+b[i]*x+c[i]);
return ans;
}
int main()
{
int tt;
scanf("%d",&tt);
while(tt--){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
l=;r=;
while(r-l>1e-){
mid=(l+r)/;
mmid=(mid+r)/;
if(f(mid)<f(mmid)) r=mmid;
else l=mid;
}
printf("%.4f\n",f(mid));
}
return ;
}
Error Curves(2010成都现场赛题)的更多相关文章
- Go Deeper(2010成都现场赛题)(2-sat)
G - Go Deeper Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description ...
- 2011 ACM/ICPC 成都赛区(为2013/10/20成都现场赛Fighting)
hdu 4111 Alice and Bob 博弈:http://www.cnblogs.com/XDJjy/p/3350014.html hdu 4112 Break the Chocolate ...
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 4788 (2013成都现场赛 H题)
100MB=10^5KB=10^8B 100MB=100*2^10KB=100*2^20B Sample Input2100[MB]1[B] Sample OutputCase #1: 4.63%Ca ...
- hdu 4465 Candy(2012 ACM-ICPC 成都现场赛)
简单概率题,可以直接由剩余n个递推到剩余0个.现在考虑剩余x个概率为(1-p)的candy时,概率为C(2 * n - x, x) * pow(p, n + 1) *pow(1 - p, n - x ...
- hdu 4465 Candy 2012 成都现场赛
/** 对于大数的很好的应用,,缩小放大,,保持精度 **/ #include <iostream> #include <cmath> #include <algorit ...
- hdu 4472 Count (2012 ACM-ICPC 成都现场赛)
递推,考虑到一n可以由i * j + 1组合出来,即第二层有j个含有i个元素的子树...然后就可以了.. #include<algorithm> #include<iostream& ...
- Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow
2018ACM-ICPC南京现场赛D题-Country Meow Problem D. Country Meow Input file: standard input Output file: sta ...
- 2013杭州现场赛B题-Rabbit Kingdom
杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...
随机推荐
- IOS开发实现录音功能
导入框架: ? 1 #import <AVFoundation/AVFoundation.h> 声明全局变量: ? 1 2 3 4 5 @interface ViewController ...
- execute、executeUpdate、executeQuery三者的区别(及返回值)
1. ResultSet executeQuery(String sql); 执行SQL查询,并返回ResultSet 对象. 2.int executeUpdate(String sql); 可执行 ...
- [原创] zabbix学习之旅四:mail客户端安装
相信大家使用zabbix的最主要目的就是当被监控机器发生故障时,能通过zabbix获得第一时间的报警提醒.zabbix常用的报警媒介有email,短信,jabber和脚本,这其中脚本类型最为灵活,尤其 ...
- 第三章DOM
1. DOM的概念 D:Document. O:Object.对象可以分为三类, 1. 用户自定义的对象. 2. 内建对象,如Array,Math,Date. 3. 宿主对象,浏览器提供的对象.如wi ...
- 开源 P2P 直播 视频会议
转自:http://blog.csdn.net/pkueecser/article/details/8223074 一个P2P点播直播开源项目:P2PCenter(我转过来的时候发现已经都打不开了.. ...
- 3243: [Noi2013]向量内积 - BZOJ
Description 两个d 维向量A=[a1,a2,...,ad]与B=[b1,b2,...,bd]的内积为其相对应维度的权值的乘积和,即: 现有 n 个d 维向量x1,...,xn ,小喵喵想知 ...
- uva 10269 最短路
求两次最短路 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...
- jQuery1.9.1源码分析--Animation模块
var fxNow, // 使用一个ID来执行动画setInterval timerId, rfxtypes = /^(?:toggle|show|hide)$/, // eg: +=30.5px / ...
- NGINX的奇淫技巧 —— 5. NGINX实现金盾防火墙的功能(防CC)
NGINX的奇淫技巧 —— 5. NGINX实现金盾防火墙的功能(防CC) ARGUS 1月13日 发布 推荐 0 推荐 收藏 2 收藏,1.1k 浏览 文章整理中...... 实现思路 当服务器接收 ...
- git安装及使用
一.安装 1.从http://code.google.com/p/msysgit/下载Git-1.8.4-preview20130916.exe,并安装. 2.新建git目录,右键选择Git Bash ...