ZOJ 3711 Give Me Your Hand
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)用运算 ...
随机推荐
- 第六次作业——利用MFC实现计算器图形界面以及简单四则运算表达式批处理
参考资料: 1.MFC响应键盘 2.计算器实例 3.MFC文件对话框 4.MFCUpdateData()函数的使用 5.MFC教程 6.wi ...
- [JavaEE]Get请求URI中带的中文参数在服务端乱码问题的解决方法
在Get请求中,如果请求参数中带有中文,如 http://localhost:8080/DinnerParty/shop/search?query=多伦多, 在服务端拿到的是乱码. 这是因为客户端提交 ...
- Appium for IOS testing on Mac
一:环境 1.Mac OS X 10.9.1 2.Xcod 5.0.2 3.Appium 1.3.6 下载地址:https://bitbucket.org/appium/appium.app/down ...
- OpenGLES入门笔记二
#import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> #import <OpenGLES/ES2/gl.h& ...
- mysql数据库中标的key的含义
四种Key: Primary Key, Unique Key, Key 和 Foreign Key. 1.如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非 ...
- libuv(不断更新)
/* * Initialize the uv_async_t handle. A NULL callback is allowed. * * Note that uv_async_init(), un ...
- Java——包的概念及使用
package是在使用多个类或接口时,为了避免名称重复而采用的一种措施,直接在程序中加入package关键字即可 编译语法: javac -d . HelloWord.java -d:表示生成目录,生 ...
- ubuntu下Eclipse下添加GBK编码
把Windows下的工程导入到了Linux下Eclipse中,由于以前的工程代码,都是GBK编码的(Windows下的Eclipse 默认会去读取系统的编码,所以Widnwos下的Eclipse的编码 ...
- jquery左边滚动,完毕后跳转回来
代码如下 function in_scroll(){ $liW = ; $num = $(".in-cy li").size(); $ulW = $liW*$num; $(&quo ...
- -- c语言数据类型总结 --
C语言中的数据类型总结