传送门

题解

//minamoto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
int read(){
int res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=1.5e5+5;
struct node{
int cnt;db val;
inline node(){}
inline node(int x,db y):cnt(x),val(y){}
inline bool operator <(const node &b)const
{return val>b.val;}
inline void in(){
static int x,y;scanf("%d/%d",&x,&y);
val=(db)x/y,scanf("%d",&cnt);
}
}A[N],B[N*3];
int n,m,tot;
inline db calc(){
db res=1e18,sum=0;ll now=1,rem=m;
for(int i=n;i;--i)sum+=(B[i].cnt-1)*B[i].val*(1-B[i].val)+(1-B[i].val)*B[i+1].val,rem-=B[i].cnt;
for(int i=1;i<=n;++i){
rem-=B[i].cnt;
while(now<=n&&rem<=0)
sum-=(B[now].cnt-1)*B[now].val*(1-B[now].val)+(1-B[now].val)*B[now+1].val,rem+=B[now++].cnt;
if(rem<=0)break;
sum+=(B[i].cnt-1)*B[i].val*(1-B[i].val)+(1-B[i-1].val)*B[i].val;
res=min(res,sum+(rem-1)*B[now-1].val*(1-B[now-1].val)+(1-B[now-1].val)*B[now].val+(1-B[i].val)*B[now-1].val);
}
rem=m,sum=0;
for(int i=1;i<=n;++i){
int mn=min(rem,(ll)B[i].cnt);
if(!mn)break;rem-=mn,sum+=(mn-1)*B[i].val*(1-B[i].val)+(1-B[i-1].val)*B[i].val;
}
return res=min(res,sum);
}
int main(){
// freopen("testdata.in","r",stdin);
int T;scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
A[i].in();if(!A[i].cnt)--i,--n;
}
sort(A+1,A+1+n),tot=0;
for(int i=1;i<=n;++i){
B[++tot]=node(1,A[i].val);
if(--A[i].cnt){
if(A[i].cnt>1)B[++tot]=node(A[i].cnt-1,A[i].val);
B[++tot]=node(1,A[i].val);
}
}
B[0].val=1,B[(n=tot)+1].val=0;
db ans=calc();
for(int i=1;i<=(n>>1);++i)swap(B[i],B[n+1-i]);
for(int i=1;i<=n;++i)B[i].val=1-B[i].val;
ans=min(ans,calc());
printf("%.6Lf\n",fabs(ans));
}
return 0;
}

P4110 [HEOI2015]小L的白日梦的更多相关文章

  1. 【BZOJ4030】[HEOI2015]小L的白日梦

    [BZOJ4030][HEOI2015]小L的白日梦 题面 BZOJ 洛谷 题解 要求的是最小的不开心连续段的期望. 然后发现自己就不会做了. 然后就可以来抄题解啦. 首先来猜性质: 第一个,一定是按 ...

  2. BZOJ 4030: [HEOI2015]小L的白日梦

    4030: [HEOI2015]小L的白日梦 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 172  Solved: 39[Submit][Statu ...

  3. HEOI2015小L的白日梦

    题面链接 洛咕 sol 为什么网上面只有神仙题解啊!!! 引起我这种蒟蒻不适QAQ. 性质证明留给巨佬 然后我只贴性质了QwQ. 1.一定存在最优解每一天不高兴的概率是单调不增的. 2.一定存在最优解 ...

  4. bzoj4030【HEOI2015】小L的白日梦

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=4030 sol  :orz Yousiki http://www.cnblogs.com/you ...

  5. 洛谷U4727小L的二叉树[树转序列 LIS]

    题目背景 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣. 所以,小L当时卡在了二叉树. 题目描述 在计算机科学中,二叉树是每个结点最多有两个子结点的 ...

  6. ACM D的小L

    D的小L 时间限制:4000 ms  |  内存限制:65535 KB 难度:2   描述       一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给 ...

  7. bzoj 4031: [HEOI2015]小Z的房间 轮廓线dp

    4031: [HEOI2015]小Z的房间 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 98  Solved: 29[Submit][Status] ...

  8. nyoj-366-D的小L(求全排列)

    D的小L 时间限制:4000 ms  |  内存限制:65535 KB 难度:2 描述       一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给匡匡 ...

  9. 洛谷U4727 小L 的二叉树

    U4727 小L 的二叉树 题目背景 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣. 所以,小L当时卡在了二叉树. 题目描述 在计算机科学中,二叉树 ...

随机推荐

  1. IntelliJ IDEA配置本地Tomcat方法---亲测有效

    https://blog.csdn.net/hello_ljl/article/details/79258165

  2. UI & 原型

    UI & 原型 产品原型设计与团队实时协作平台 https://www.xiaopiu.com/download https://www.xiaopiu.com/forum/posts/5b9 ...

  3. UVA 1995 I can guess the structer

    模 拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #inclu ...

  4. ajax分页查询信息的通用方法

    1.页面准备分页的表格与分页div 同时需要在查询条件表单中准备隐藏当前页与页大小的文本框 <div class="container-fluid"> <div ...

  5. Redis 配置【十】

    参考:http://www.runoob.com/redis/redis-conf.html Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf. 你可以通过 CONF ...

  6. POJ 3518 (后缀自动机)

    POJ 3518 Boring Problem : 给一个串S,询问串S有多个子串出现至少两次且位置不重叠. Solution : 对S串建立后缀自动机,再建立后缀树,dfs一遍统计处每个结点的子树中 ...

  7. Rikka with Phi 线段树

    Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds ...

  8. 18.9.22 noip模拟赛

    此题为找规律.期望100 实际100 #include<cstdio> #include<cstring> #include<iostream> #include& ...

  9. 记一次调试python内存泄露的问题

    转载:http://www.jianshu.com/p/2d06a1a01cc3 这两天由于公司需要, 自己编写了一个用于接收dicom文件(医学图像文件)的server. 经过各种coding-de ...

  10. 赵雅智_Android的getResources()资源引用

    今天做一个Android的刮刮乐项目.里面用到非常多的地方用到了getResources. <span style="font-size:12px;"> // 获得图片 ...