UVA 1476 1476 - Error Curves

题目链接

题意:给几条下凹二次函数曲线。然后问[0,1000]全部位置中,每一个位置的值为曲线中最大值的值,问全部位置的最小值是多少

思路:三分法,因为都是下凹函数,所以全部曲线合并起来。仍然是一个下凹函数。满足单峰。用三分求极值

代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. const int N = 10005;
  8. int t, n, ans;
  9. struct Line {
  10. double a, b, c;
  11. } l[N];
  12.  
  13. double cal(double x) {
  14. double ans = l[0].a * x * x + l[0].b * x + l[0].c;
  15. for (int i = 1; i < n; i++)
  16. ans = max(ans, l[i].a * x * x + l[i].b * x + l[i].c);
  17. return ans;
  18. }
  19.  
  20. double solve() {
  21. double l = 0, r = 1000;
  22. while (fabs(l - r) > 1e-9) {
  23. double ml = (2 * l + r) / 3;
  24. double mr = (l + 2 * r) / 3;
  25. if (cal(ml) < cal(mr)) r = mr;
  26. else l = ml;
  27. }
  28. return cal(l);
  29. }
  30.  
  31. int main() {
  32. scanf("%d", &t);
  33. while (t--) {
  34. scanf("%d", &n);
  35. for (int i = 0; i < n; i++)
  36. scanf("%lf%lf%lf", &l[i].a, &l[i].b, &l[i].c);
  37. printf("%.4lf\n", solve());
  38. }
  39. return 0;
  40. }

UVA 1476 - Error Curves(三分法)的更多相关文章

  1. 【单峰函数,三分搜索算法(Ternary_Search)】UVa 1476 - Error Curves

    Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...

  2. UVA - 1476 Error Curves 三分

                                           Error Curves Josephina is a clever girl and addicted to Machi ...

  3. uva 1476 - Error Curves

    对x的坐标三分: #include<cstdio> #include<algorithm> #define maxn 10009 using namespace std; do ...

  4. UVA 5009 Error Curves

    Problem Description Josephina is a clever girl and addicted to Machine Learning recently. She pays m ...

  5. LA 5009 (HDU 3714) Error Curves (三分)

    Error Curves Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPr ...

  6. Error Curves(2010成都现场赛题)

    F - Error Curves Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Descript ...

  7. Error Curves HDU - 3714

    Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a m ...

  8. hdu 3714 Error Curves(三分)

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  9. HDU 3714/UVA1476 Error Curves

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

随机推荐

  1. MFC_2.10选项卡控件的封装

    选项卡控件的封装 1.新建默认MFC项目 2.添加资源Dialog,属性style改child,边框改none,添加类取名CMyDialog1: 同理,CMyDialog2: 3.类向导,添加MFC类 ...

  2. vba txt读写的几种方式

    四种方式写txt 1.这种写出来的是ANSI格式的txt Dim TextExportFile As String TextExportFile = ThisWorkbook.Path & & ...

  3. TypeError: 'TestCase' object is not iterable

    这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...

  4. blender--(凹凸贴图)................https://jingyan.baidu.com/article/9f63fb917c4becc8400f0ea8.html

    在blender中直接绘制模型凹凸纹理细节 听语音 | 浏览:32 | 更新:2018-02-20 11:18 1 2 3 4 5 6 7 分步阅读 在blender中为了表现更多的模型细节,我们会常 ...

  5. nz-card头部右侧添加东西

    <nz-card [nzBordered]="true" nzTitle="卡片标题" [nzExtra]="extraTemplate1&qu ...

  6. 出生年 (15 分) C解法

    出生年 以上是新浪微博中一奇葩贴:"我出生于1988年,直到25岁才遇到4个数字都不相同的年份."也就是说,直到2013年才达到"4个数字都不相同"的要求.本题 ...

  7. 洛谷——P2094 运输

    P2094 运输 题目描述 现在已知N件商品,和搬运它们其中每一件的费用.现在搬家公司老板Mr.sb决定让我们每次任意选取2件商品.然后这2件商品只算一件商品的费用.但是这个商品的搬运费用是将选出的2 ...

  8. Java中对象流使用的一个注意事项

    再写jsp的实验作业的时候,需要用到java中对象流,但是碰到了之前没有遇到过的情况,改bug改到崩溃!!记录下来供大家分享 如果要用对象流去读取一个文件,一定要先判断这个文件的内容是否为空,如果为空 ...

  9. 二: 安装centos服务环境软件mysql httpd php

    安装mysql--------------------------------------wget http://dev.mysql.com/get/mysql-community-release-e ...

  10. 关于一个css布局的小记录

    这里我们采用一种最简单的 方式,至少我目前认为最简单的方式,使用flex布局来实现 下面是html结构: <div class="box1"> <div clas ...