备战省赛4 问题 E: LED;

备战省赛4 问题 E: LED;

添加链接描述
感觉题意为 求一个使 分段函数合法的 最小误差值(由最大值和最小值确定,所以二分,感觉他给的值有问题把 两个 109 109,所以刚开始暴力做的,提示re 素组开小 了 所以不是109的范围感觉,emmmmmmmmm 二分最小误差值 然后验证。)
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

发光二极管(LED)是半导体光源,当电压高于阈值的电流施加到其引线上时发光。ACM研发部最近报告说,他们已经成功开发出一种新的LED,即Acmoled。Acmoled具有一种特殊的行为,即当电流电压增加时,从它发出的光强度分两步变化,如下图所示。

如图所示,在0到v1的电压范围内,未激活Acmoled,而当电压达到第一阈值v1时,它发出强度l1≥0的光,当电压达到x阈值v2时,它发出强度l2≥l1的光。更具体地说,如果f(v)是将电压v映射到从无钼酸盐发出的光强度的函数,那么对于4个实数l1、l2、v1和v2,0≤l1≤l2和0<v1<v2,我们有

现在的问题是,ACM研发人员仍然不知道两个阈值电压值v1和v2以及两个强度值l1和l2的确切值。ACM研发的研究人员计划通过反复的实验来估计这四种药物的含量。
实验是通过施加特定电压的电流和观察从无钼酸盐发出的光的强度来完成的。经过n次不同电压值的重复实验,得到n个元组(v1,l1),(v2,l2),…,(vn,ln)的数据,其中li是电压vi的观测强度,由于观测装置不精确等原因,实验数据不准确,可能存在一定的误差。尽管如此,他们还是希望找到一个最佳的估计强度函数f(v),以最小化以下误差函数:

其中x表示实数x的绝对值。
对于n个元组的给定数据,编写一个程序,找到一个估计强度函数f,使上述误差函数最小化,并输出误差值(f)。

内幕

您的程序将从标准输入中读取。输入以包含整数n(1≤n≤300000)的行开始,其中n是实验数据中的元组数(vi,li)。在下面的n行中,每行包含两个整数,范围从0到109,表示实验数据的每个元组(vi,li)中的vi和li。注意,您可以假设输入中没有两个元组(vi,li)和(vj,lj),这样1≤i<j≤n和vi=vj。

特技

您的程序将写入标准输出。只打印一行,由一个实数组成,四舍五入到小数点后一位,表示最小误差值(f)。

附带条件
复制样品数据5
0 0
2 1
3 5
6 7
7 11

附带条件

#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll max(ll a,ll b)
{
    return a>=b?a:b;
}
ll min(ll a,ll b)
{
    return a<=b?a:b;
}
ll n;
struct node{
ll v;
ll l;
}a[312345];
bool cmd(node x,node y)
{
    return x.v<y.v;
}
ll check(ll x)
{
    ll l1,l2;
    int i;
    for(i=1;i<=n;++i)
    {
        if(a[i].l>x)
            break;
    }
    if(i>n)
        return 1;
    ll Max=0,Min=1e11;
    for(;i<=n;++i)
    {
        Max=max(Max,a[i].l);
        Min=min(Min,a[i].l);
        if( (Max-Min)/2>x )
            break;
    }
    l1=(Max+Min)/2;
    if(i>n)
        return 1;
    Max=0,Min=1e11;
    for(;i<=n;++i)
    {
        Max=max(Max,a[i].l);
        Min=min(Min,a[i].l);
        if( (Max-Min)/2>x )
            break;
        l2=(Max+Min)/2;
    }
    if(i<=n)
        return 0;
    return l2>=l1;
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&a[i].v,&a[i].l);
        a[i].l=a[i].l*10;
    }
    sort(a,a+1+n,cmd);
    ll base=0,j=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i].v==0)
            base=max(a[i].l,base);
        else
            a[++j]=a[i];
    }
    n=j;
    ll r=1e11,l=0,res=-1;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if(check(mid))
        {
            res=mid;
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }
    }
    res=max(base,res);
    ll x=res%10;
    res=res/10;
    printf("%lld.%lld\n",res,x);
    return 0;
}

发布了18 篇原创文章 · 获赞 7 · 访问量 993

猜你喜欢

转载自blog.csdn.net/qq_43559193/article/details/89220953
e4e
led
今日推荐