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\n", r);
    return 0;
}

 

转载于:https://www.cnblogs.com/albert-biu/p/10666016.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值