Give Me Your Hand
Time Limit: 2 Seconds Memory Limit: 131072 KB Special Judge
BellyWhite and MightyHorse are two students of Marjar University. They are best friends and also roommates living in the same dorm. There are K students living in that dorm, including BellyWhite and MightyHorse.
BellyWhite posted a strange microblog in 2012-9-3:
This is quite strange. It means that BellyWhite will chop some "hands" into pieces if he's been found playing games or some other activities which is not relevant to his research. This logic is insane, isn't it?
We could call those things which are not relevant to BellyWhite's research "bad things". Now we know that BellyWhite will start doing bad things when he's in the dorm for T minutes, and he will stop doing those things when he's being warned by MightyHorse or leaving the dorm. If he's been warned to stop doing bad things and then he stays in the dorm for another T minutes, he will start doing bad things again.
MightyHorse noticed the strange microblog BellyWhite posted, but he's a good roommate, so he must took the risk of losing his "hands" to warn BellyWhite that he was doing something harmful to his research progress or even his PhD degree. Fortunately, MightyHorse has M plastic toy "hands", so BellyWhite will only chop those toy hands into pieces when he's being warned.
Here comes the problem. We only know that no one is in the dorm initially, and we heard N door open and close sounds, which means there are N people entered or exited the dorm. We logged exact time of all door sounds, but we don't know who made the sound, that means all K students living in the dorm have the same possibility to enter / exit. We'd like to know the expected number of toy hands MightyHorse will have after 24 hours (1440 minutes).
Please note that using toy hand to stop BellyWhite from doing bad things take no time, which means that even at the moment MightyHorse or BellyWhite enter / exit the dorm, a toy hand will be used to stop the bad thing. But if that there's no toy hand left, MightyHorse will not able to stop BellyWhite from doing bad things.
Input
There are multiple test cases. The first line of input is an integer Casenum indicating the number of test cases.
For each test case, the first line contains 4 integers T (1 ≤ T ≤ 100), N (1 ≤ N ≤ 100), M (1 ≤ M ≤ 100) and K (2 ≤ K ≤ 8) which are defined in descriptions above.
The following line contains N integers. For every integer ti(0 ≤ ti ≤ 1440, 0 ≤ i < N), it means that a student entered or exited the dorm at time ti.
We guarantee that all those N ti will be given in strictly increasing order.
Output
For each test case, output the expected number of toy hands that MightyHorse still have at time 1440, rounded to 6 decimal points.
Sample Input
260 2 10 2200 260100 2 8 51340 1341
Sample Output
5.0000007.960000
Author: FAN, Yuzhe
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; double dp[][][][];
///dp[第几次][位置关系][被警告一次后再屋内待了多久][剩下几只手]=概率
int t[]; int ca,T,N,M,K; int main()
{
scanf("%d",&ca);
while(ca--)
{
scanf("%d%d%d%d",&T,&N,&M,&K);
memset(dp,,sizeof(dp));
dp[][][][M]=1.0;t[]=;
for(int i=;i<=N;i++)
{
scanf("%d",&t[i]);
int ti=t[i]-t[i-];
///state 0: b X m X
for(int j=;j<=M;j++)
{
dp[i][][][j]+=dp[i-][][][j]*(K-.)*./K;
dp[i][][][j]+=dp[i-][][][j]*./K;
dp[i][][][j]+=dp[i-][][][j]*./K;
}
///state 1: b X m Y
for(int j=;j<=M;j++)
{
dp[i][][][j]+=dp[i-][][][j]*./K;
dp[i][][][j]+=dp[i-][][][j]*(K-.)*./K;
dp[i][][][j]+=dp[i-][][][j]*./K;
}
///state 2 b Y m X
for(int k=;k<=T;k++)
{
for(int j=;j<=M;j++)
{
dp[i][][][j]+=dp[i-][][k][j]*./K;
dp[i][][min(T,k+ti)][j]+=dp[i-][][k][j]*(K-.)*./K;
dp[i][][(k+ti)>=T?:(k+ti)][max(,j-((k+ti)>=T))]+=dp[i-][][k][j]*./K;
}
}
///state 3 b Y m Y
for(int k=;k<=T;k++)
{
for(int j=;j<=M;j++)
{
dp[i][][][max(,j-(k+ti)/T)]+=dp[i-][][k][j]*./K;
dp[i][][(k+ti)%T][max(,j-(k+ti)/T)]+=dp[i-][][k][j]*./K;
dp[i][][(k+ti)%T][max(,j-(k+ti)/T)]+=dp[i-][][k][j]*(K-.)/K;
}
}
}
double ans=.;
for(int i=;i<=T;i++)
{
for(int j=;j<=;j++)
{
for(int k=;k<=M;k++)
{
ans+=dp[N][j][i][k]*k;
}
}
}
int ti=-t[N];
for(int i=;i<=T;i++)
{
for(int j=;j<=M;j++)
{
ans+=dp[N][][i][j]*max(,j-(i+ti)/T);
}
}
printf("%.6lf\n",ans);
}
return ;
}
ZOJ 3711 Give Me Your Hand的更多相关文章
-
ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
-
ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
-
ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
-
ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
-
ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
-
ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
-
ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
-
zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
-
ZOJ 1958. Friends
题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...
随机推荐
-
Unity插件使用总结
移动文件夹位置会引起错误的插件:EasySave2.MaterialUI.Gamestrap UI.Beautify
-
Linux后台执行脚本文件,nohup
看运维人员执行nohup命令后,把程序放在后台执行,很高大上,就研究了一下,这个命令. nohup命令及其输出文件 nohup命令:如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么 ...
-
openssl API网络通信
1.本文是在别人的基础上,经过测试,大体总结的.操作环境ubuntu12和ubuntu14 ****************************************************** ...
-
OC中NSDictionary(字典)、NSMutableDictionary(可变字典)、NSSet(集合)、NSMutableSet(可变集合)得常用方法
字典用于保存具有映射关系数据的集合 一个key—value对认为是一个条目(entry),字典是存储key—value对的容器 与数组不同,字典靠key存取元素 key不能重复,value必须是对象 ...
-
mac 开发必备软件(不断update ing...)
整理下mac环境下, 开发必备的一些软件吧, 由于不断要更新ing, 用到啥就写啥~球轻拍 1.host 绑定切换神器 a.gas mask : 只能切换单个自定义的host文件 b.ihosts(推 ...
-
ajaxFileUpload 报这错jQuery.handleError is not a function 博客分类: WEB前端jquery
ajaxfileuploadhandleError 今天刚打个一个技术群,里面有人问标题上的问题,嘿,我恰好遇过,现在大家至少也在用jquery1.9以上的版本,ajaxfileupload的版本早 ...
-
Mysql和Oracle的一些语法区别
作为一个有追求的程序猿,当然要不断的学习,巴拉巴拉巴拉...好了,贴一个网址给大家,哈哈 MySQL与Oracle 差异比较:http://www.cnblogs.com/HondaHsu/p/364 ...
-
linux 命令mkdir、cd
mkdir 创建文件夹 -p 递归创建文件夹 可以一次性创建多个目录 cd pwd 显示当前目录的绝对路径 rmdir 删除空目录 只能删除空目录 鸡肋,基本用rm cp 复制文件产品 -r ...
-
MYSQL时间类别总结: TIMESTAMP、DATETIME、DATE、TIME、YEAR
总结背景: 对于MYSQL数据库日期类型或多有了解, 但并很清晰其中一些规则. 基本都是面向浏览器编码, 这实质上也是一种方式. 但期间遇到两个问题: 时常遇到建表中出现多个datetime或者ti ...
-
正则,re模块
一.正则表达式(精准匹配) 匹配字符串内容的一种规则 二.字符组 在同一个位置可能出现的各种字符组成了一个字符组,在正则表达式中用[]表示 常见字符组格式如下:[0123456789],[0-9],[ ...