leeing Sunlight(二分)

Klee's definition of playing is throwing explosives all over the place; she is particularly fond of "fish blasting'' --- throwing bombs in lakes full of fish.

Today, Klee also plans to blast fish in Starfell Lake. There are n fish in Starfell Lake. Klee will use a bomb with power x, then, every fish whose HP less than or equal to x will be blasted.

However, Klee doesn't know HP of every fish. Instead, she only knows HP of the i-th fish is a uniformly random real number in [li,ri][l_i, r_i][li,ri]. Now, Klee wants to determine minimum possible x such that the expected number of blasted fish is greater or equal to m.

Your answer will be considered correct, if its absolute or relative error does not exceed 10−410^{-4}104 . More formally, if your answer is a and jury's answer is b, your answer will be considered correct if ∣a−b∣max⁡(1,b)≤10−4\frac{|a-b|}{\max(1,b)} \leq 10^{-4}max(1,b)ab104 .

输入描述:

The first line contains two integers n, m (1≤m≤n≤1051 \leq m \leq n \leq 10^51mn105) --- the number of fish and Klee's expection of the number of blasted fish.

In the following n line, each line contains two real numbers li,ril_i, r_ili,ri (0≤li≤ri≤1090 \leq l_i \leq r_i \leq 10^90liri109), which means HP of the i-th fish will be a random real number in [li,ri][l_i, r_i][li,ri].

输出描述:

Output minimum possible x such that the expected number of blasted fish is greater or equal to m.
示例1

输入

复制 2 1 1.4 2.8 1.4 2.8
2 1
1.4 2.8
1.4 2.8

输出

复制 2.1000000000
2.1000000000
示例2

输入

复制 3 2 1.5 3.0 2.4 5.0 1.919810 1.919810
3 2
1.5 3.0
2.4 5.0
1.919810 1.919810

输出

复制 2.7804878048
2.7804878048
示例3

输入

复制 1 1 0 1000000000
1 1
0 1000000000

输出

复制 1000000000.0000000000
1000000000.0000000000

备注:

In the first example, if Klee throws a bomb with power 2.1, the probability for blasting fish 1 is 0.5, the probability for blasting fish 2 is 0.5, so the expection of the number of blasted fish is 0.5+0.5=1.

In the second example, if Klee throws a bomb with power 11441≈2.7804878048\frac{114}{41} \approx 2.7804878048411142.7804878048, the probability for blasting fish 1 is 3541\frac{35}{41}4135, the probability for blasting fish 2 is 641\frac{6}{41}416, the probability for blasting fish 3 is 1, so the expection of the number of blasted fish is 3541+641+1=2\frac{35}{41}+\frac{6}{41}+1=24135+416+1=2.
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
struct pairs
{
    double l,r;
}seg[maxn];
const double exps=1e-5;
int n;
int maybe;
double sgs[maxn];
double per;
int i;
inline bool judge(double t)
{
    per=0.0;
    for(i=1;i<=n;i++){
        if(t<seg[i].l)per+=0;
        else if(t>seg[i].r)per+=1;
        else per+=(t-seg[i].l)/(sgs[i]);
        if(per>=maybe)return true;
    }
    return false;
}
void solve()
{
    double maxx=0.0,minn=0x3f3f3f3f;
    for( i=1;i<=n;i++){
        scanf("%lf%lf",&seg[i].l,&seg[i].r);
        sgs[i]=seg[i].r-seg[i].l;
        maxx=max(maxx,seg[i].r);
        minn=min(minn,seg[i].l);
    }
    double l=minn-1,r=maxx+1;
    double mid;
    while(r-l>exps)
    {
         mid=(l+r)/2;
        if(judge(mid))r=mid;
        else l=mid;
    }
    printf("%.10lf\n",r);
}
int main()
{
    scanf("%d%d",&n,&maybe);
    solve();
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值