UVA 1476 - Error Curves(三分法)
UVA 1476 1476 - Error Curves
题意:给几条下凹二次函数曲线。然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少
思路:三分法,因为都是下凹函数,所以全部曲线合并起来。仍然是一个下凹函数。满足单峰。用三分求极值
代码:
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- const int N = 10005;
- int t, n, ans;
- struct Line {
- double a, b, c;
- } l[N];
- double cal(double x) {
- double ans = l[0].a * x * x + l[0].b * x + l[0].c;
- for (int i = 1; i < n; i++)
- ans = max(ans, l[i].a * x * x + l[i].b * x + l[i].c);
- return ans;
- }
- double solve() {
- double l = 0, r = 1000;
- while (fabs(l - r) > 1e-9) {
- double ml = (2 * l + r) / 3;
- double mr = (l + 2 * r) / 3;
- if (cal(ml) < cal(mr)) r = mr;
- else l = ml;
- }
- return cal(l);
- }
- int main() {
- scanf("%d", &t);
- while (t--) {
- scanf("%d", &n);
- for (int i = 0; i < n; i++)
- scanf("%lf%lf%lf", &l[i].a, &l[i].b, &l[i].c);
- printf("%.4lf\n", solve());
- }
- return 0;
- }
UVA 1476 - Error Curves(三分法)的更多相关文章
- 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- UVA - 1476 Error Curves 三分
Error Curves Josephina is a clever girl and addicted to Machi ...
- uva 1476 - Error Curves
对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...
- UVA 5009 Error Curves
Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...
- LA 5009 (HDU 3714) Error Curves (三分)
Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatusPr ...
- Error Curves(2010成都现场赛题)
F - Error Curves Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descript ...
- Error Curves HDU - 3714
Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...
- hdu 3714 Error Curves(三分)
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 3714/UVA1476 Error Curves
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- MFC_2.10选项卡控件的封装
选项卡控件的封装 1.新建默认MFC项目 2.添加资源Dialog,属性style改child,边框改none,添加类取名CMyDialog1: 同理,CMyDialog2: 3.类向导,添加MFC类 ...
- vba txt读写的几种方式
四种方式写txt 1.这种写出来的是ANSI格式的txt Dim TextExportFile As String TextExportFile = ThisWorkbook.Path & & ...
- TypeError: 'TestCase' object is not iterable
这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...
- blender--(凹凸贴图)................https://jingyan.baidu.com/article/9f63fb917c4becc8400f0ea8.html
在blender中直接绘制模型凹凸纹理细节 听语音 | 浏览:32 | 更新:2018-02-20 11:18 1 2 3 4 5 6 7 分步阅读 在blender中为了表现更多的模型细节,我们会常 ...
- nz-card头部右侧添加东西
<nz-card [nzBordered]="true" nzTitle="卡片标题" [nzExtra]="extraTemplate1&qu ...
- 出生年 (15 分) C解法
出生年 以上是新浪微博中一奇葩贴:"我出生于1988年,直到25岁才遇到4个数字都不相同的年份."也就是说,直到2013年才达到"4个数字都不相同"的要求.本题 ...
- 洛谷——P2094 运输
P2094 运输 题目描述 现在已知N件商品,和搬运它们其中每一件的费用.现在搬家公司老板Mr.sb决定让我们每次任意选取2件商品.然后这2件商品只算一件商品的费用.但是这个商品的搬运费用是将选出的2 ...
- Java中对象流使用的一个注意事项
再写jsp的实验作业的时候,需要用到java中对象流,但是碰到了之前没有遇到过的情况,改bug改到崩溃!!记录下来供大家分享 如果要用对象流去读取一个文件,一定要先判断这个文件的内容是否为空,如果为空 ...
- 二: 安装centos服务环境软件mysql httpd php
安装mysql--------------------------------------wget http://dev.mysql.com/get/mysql-community-release-e ...
- 关于一个css布局的小记录
这里我们采用一种最简单的 方式,至少我目前认为最简单的方式,使用flex布局来实现 下面是html结构: <div class="box1"> <div clas ...