• UVaLive 5009 Error Curves (三分)


    题意:给定 n 条二次曲线, fi(x) = aix^2 + bix + c 定义 F(x) =max{Si(x)},求 F(x) 在 0 ~ 1000 上的最小值。

    析:从题目给定的曲线上进行分析,很容易知道,最后的所形成的图形一定是下凸的,而这个图形就一定有一个最小值,而下凸函数可以用三分来求解。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #include <list>
    #include <assert.h>
    #include <bitset>
    #include <numeric>
    #define debug() puts("++++")
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a, b, sizeof a)
    #define sz size()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    #define lowbit(x) -x&x
    //#define all 1,n,1
    #define FOR(i,n,x)  for(int i = (x); i < (n); ++i)
    #define freopenr freopen("in.in", "r", stdin)
    #define freopenw freopen("out.out", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e17;
    const double inf = 1e20;
    const double PI = acos(-1.0);
    const double eps = 1e-10;
    const int maxn = 10000 + 5;
    const int maxm = 1e6 + 2;
    const LL mod = 1000000007;
    const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
    const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c) {
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int a[maxn], b[maxn], c[maxn];
    
    double F(double x){
      double ans = a[0] * sqr(x) + b[0] * x + c[0];
      for(int i = 1; i < n; ++i)
        ans = max(ans, a[i] * sqr(x) + b[i] * x + c[i]);
      return ans;
    }
    
    int main(){
      int T;  cin >> T;
      while(T--){
        scanf("%d", &n);
        for(int i = 0; i < n; ++i)  scanf("%d %d %d", a+i, b+i, c+i);
        double l = 0., r = 1000.;
        while(r - l > eps){
          double m1 = l + (r-l)/3.;
          double m2 = r - (r-l)/3;
          if(F(m1) < F(m2))  r = m2;
          else l = m1;
        }
        printf("%.4f
    ", F(l));
      }
      return 0;
    }
    

      

  • 相关阅读:
    莫队模板
    CF600E Lomsat gelral
    JZOJ 捕老鼠
    JZOJ 4896. 【NOIP2016提高A组集训第16场11.15】兔子
    JZOJ 4895【NOIP2016提高A组集训第16场11.15】三部曲
    双端队列xLIS问题
    最大K段和
    你真的了解ES6的promise吗?
    JS对象和数组深浅拷贝总结②
    当前页码删除唯一数据后加载前一页内容
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/8608923.html
Copyright © 2020-2023  润新知