博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Error Curves(2010成都现场赛题)
阅读量:5902 次
发布时间:2019-06-19

本文共 2771 字,大约阅读时间需要 9 分钟。

F - Error Curves

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.

 

Quadric Function

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

212 0 022 0 02 -4 2

Sample Output

0.00000.5000

 

简单三分。

可以证明,许多二次函数f取其最大即F(x)=max(f(x))依然为下凸函数,类似二次函数。

便可进行三分处理。

 

#include
#include
#include
#define max(x,y) ((x)<(y)?(y):(x))double l,r,a[10005],b[10005],c[10005],mid,mmid;int n;double f(double x){ double ans=-1000000000; for(int i=1;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=1;i<=n;i++) scanf("%lf%lf%lf",&a[i],&b[i],&c[i]); l=0;r=1000; while(r-l>1e-10){ mid=(l+r)/2; mmid=(mid+r)/2; if(f(mid)

转载于:https://www.cnblogs.com/Mathics/p/3866852.html

你可能感兴趣的文章
MySQL(8)--Cluster 7.4 rpm centos7
查看>>
hdu 1292 &quot;下沙野骆驼&quot;ACM夏令营 (递推)
查看>>
python3入门教程
查看>>
明智行动的艺术2
查看>>
keycloak && docker安装 &&spring boot 集成使用
查看>>
fastjson的使用
查看>>
关于Unity中的NGUI精灵
查看>>
jq dom不存在时绑定事件
查看>>
Centos7中安装Docker
查看>>
spring4.0之五:@Conditional在满足特定条件下,才会实例化对象
查看>>
Android PullToRrefresh 自定义下拉刷新动画 (listview、scrollview等)
查看>>
Spring MVC-视图解析器(View Resolverr)-资源包视图解析器(Resource Bundle View Resolver)示例(转载实践)...
查看>>
Java 容器
查看>>
python学习:Dmidecode系统信息(一)
查看>>
50种方法优化SQL Server数据库查询
查看>>
测试过程报错
查看>>
堆排序
查看>>
实现celery中出现拥挤队列时,及时发邮件通知
查看>>
从入门到精通之Boyer-Moore字符串搜索算法详解
查看>>
Oracle使用expdp/impdp导出导入数据
查看>>