zoukankan      html  css  js  c++  java
  • UPC10880 LED

    时间限制: 2 Sec  内存限制: 512 MB
    提交: 246  解决: 13
    [提交] [状态] [命题人:admin]

    题目描述

    A Light-Emitting Diode (LED) is a semiconductor light source, which emits light when an electric current of voltage higher than a threshhold is applied to its leads. ACM R&D recently reported that they have succesfully developed a new LED, namely, ACMOLED. An ACMOLED has a special behavior that the intensity of light emitted from it changes in two steps as the voltage of the electric current increases, as depicted in the graph below.
    As shown, an ACMOLED is not activated in the voltage range from 0 to V1, while it emits light with intensity L1 ≥ 0 when the voltage reaches the first threshold V1 and light with intensity L2 ≥ L1 when the voltage reaches the x threshold V2. More specifically, if F(v) is the function that maps voltage v to the intensity of light emitted from an ACMOLED, then for four real numbers L1, L2, V1, and V2 with 0 ≤ L1 ≤ L2 and 0 < V1 < V2, we have
    The very issue now is that ACM R&D still does not know the exact values of two threshold voltage values V1 and V2 and the two intensity values L1 and L2 as well. Researchers in ACM R&D plan to estimate these four values for ACMOLEDs by repeated experiments.
    Experiments are performed by applying current of a specific voltage and observing the intensity of light emitted from an ACMOLED. After n repeated experiments with different voltage values, obtained are the data of n tuples (v1, l1), (v2, l2), ..., (vn, ln), where li is the observed intensity for voltage vi. Due to the impreciseness of the observing device and other reasons, the experimental data are not accurate and may contain some error. Nonetheless, they want to find a best estimated intensity function F(v) that minimizes the following error function:
    where |x| denotes the absolute value of a real number x.
    For a given data of n tuples, write a program that finds an estimated intensity function F that minimizes the above error function and outputs the value of error(F).

    输入

    Your program is to read from standard input. The input starts with a line containing an integer n (1 ≤ n ≤ 300,000), where n is the number of tuples (vi, li) in the experimental data. In the following n lines, each line contains two integers, which range inclusively from 0 to 109, representing vi and li in each tuple (vi, li) of the experimental data. Note that you may assume that there are no two tuples (vi, li) and (vj, lj) in the input such that 1 ≤ i < j ≤ n and vi = vj.

    输出

    Your program is to write to standard output. Print exactly one line consisting of one real number, rounded to the first decimal place, which represents the minimum value of error(F).

    样例输入

    5
    0 0
    2 1
    3 5
    6 7
    7 11
    

    样例输出

    1.0




    #include<bits/stdc++.h>
     
    using namespace std;
    const int inf = 0x3f3f3f3f;
    const int maxn = 3e5 + 1000;
    int n;
    struct node {
        double v, l;
    } e[maxn];
     
    bool cmp(node a, node b) {
        return a.v < b.v;
    }
     
    bool check(double x) {
       // cout << "x " << x << endl;
        int cnt = 1;
        double maxx = -1, minn = inf;
        int i = 0;
        double last = -1;
        double ta = -1, ti = inf;
        for (i = 0; i < n; i++) {
            if (e[i].v == 0 && e[i].l > x) return false;
            maxx = max(maxx, e[i].l);
            minn = min(minn, e[i].l);
            if (maxx > x) break;
            last = maxx;
        }
        maxx = -1, minn = inf;
        //cout << 1 << " " << i << " " << last << endl;
     
        double now;
        for (; i < n; i++) {
            if (e[i].v == 0 && e[i].l > x) return false;
            maxx = max(maxx, e[i].l);
            minn = min(minn, e[i].l);
            if (minn + x <= last && maxx - x <= last) break;
     
            if ((maxx - minn) / 2 > x) break;
            now = (maxx + minn) / 2;
        }
        last = now;
        maxx = -1, minn = inf;
        //cout << 2 << " " << i << " " << last << endl;
        for (; i < n; i++) {
            if (e[i].v == 0 && e[i].l > x) return false;
            maxx = max(maxx, e[i].l);
            minn = min(minn, e[i].l);
            if (minn + x <= last && maxx - x <= last) break;
            if ((maxx - minn) / 2 > x) break;
        }
    //    cout << 3 << " " << i << " " << last << endl;
    //    cout << "i " << i << " n " << n << endl;
    //    cout << endl;
        return i == n;
    }
     
    int main() {
        //freopen("input.txt", "r", stdin);
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%lf %lf", &e[i].v, &e[i].l);
        }
     
        sort(e, e + n, cmp);
    //    for (int i = 0; i < n; i++)
    //        cout << e[i].v << " " << e[i].l << endl;
        double l = 0, r = 2e9, mid;
        while (r - l > 0.01) {
            mid = (l + r) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        printf("%.1f
    ", r);
        return 0;
    }
  • 相关阅读:
    项目目标文档
    系统利益相关者描述案例
    软件需求模式 读书笔记二
    软件需求分析 读书笔记1
    专业实训题目需求分析
    2015年秋季个人阅读计划
    CodeVs 1615 数据备份
    HDU 3900 Unblock Me
    HDU 5898 odd-even number
    HDU 5877 Weak Pair
  • 原文地址:https://www.cnblogs.com/albert-biu/p/10666016.html
Copyright © 2011-2022 走看看