HDU 4576 Robot (概率 & 期望)
Robot
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 779 Accepted Submission(s): 304

At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the robot. A command will make the robot walk some distance. Unfortunately the direction part on the remote control is broken, so for every command the robot will chose a direction(clockwise or anticlockwise) randomly with equal possibility, and then walk w cells forward.
Michael wants to know the possibility of the robot stopping in the cell that cell number >= l and <= r after m commands.
Each test case contains several lines.
The first line contains four integers: above mentioned n(1≤n≤200) ,m(0≤m≤1,000,000),l,r(1≤l≤r≤n).
Then m lines follow, each representing a command. A command is a integer w(1≤w≤100) representing the cell length the robot will walk for this command.
The input end with n=0,m=0,l=0,r=0. You should not process this test case.
1
5 2 4 4
1
2
0 0 0 0
0.2500
题意:给你一个n,m,l,r。n个格子围成一个圈,一个机器人从第一个格子开始,经过m个步,每个步知道走几格,但是不知道方向,问你最后在l到r之间的概率。
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,m,l,r;
double dp[][N]; int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d%d%d",&n,&m,&l,&r)){
if(n== && m== && l== && r==)
break;
for(int i=;i<=n;i++)
dp[][i]=;
dp[][]=;
int x,cur=;
while(m--){
scanf("%d",&x);
for(int i=;i<n;i++)
dp[cur^][i]=;
for(int i=;i<n;i++){
if(dp[cur][i]==)
continue;
dp[cur^][((i-x)%n+n)%n]+=0.5*dp[cur][i];
dp[cur^][(i+x)%n]+=0.5*dp[cur][i];
}
cur^=;
}
double ans=;
for(int i=l-;i<r;i++) //注意这里的范围
ans+=dp[cur][i];
printf("%.4lf\n",ans);
}
return ;
}
HDU 4576 Robot (概率 & 期望)的更多相关文章
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...
- HDU 4576 Robot (概率DP)
暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...
- HDU 4576 Robot (很水的概率题)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- HDU 4576 Robot(概率dp)
Robot Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Sub ...
- HDU - 4576 Robot(概率dp+滚动数组)
题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1. ...
- HDU 4576 简单概率 + 滚动数组DP(大坑)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 坑大发了,居然加 % 也会超时: #include <cstdio> #includ ...
- HDU 4576 Robot
思路 概率dp 既然是求概率,顺推 显然有转移\(dp[i][j]=dp[i-1][j-w]/2+dp[i-1][w]/2\) 然后是环,注意特判一下 环上不要用取模处理循环的情况,会被卡常 代码 # ...
- hdu 4576(简单概率dp | 矩阵优化)
艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle? 感觉很不公平.大家算法都一致,因为我程序没有那 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
随机推荐
- Pandas python
原文: https://github.com/catalystfrank/Python4DataScience.CH 和大熊猫们(Pandas)一起游戏吧! Pandas是Python的一个 ...
- SharePoint 2010/2013: List view Lookup threshold uncovered
SharePoint with Large lists is common scenario in any Sharepoint deployment. While there are Several ...
- centos6默认python2.6升级2.7 卸载python2.6升级2.7
转自:http://blog.csdn.net/u010098331/article/details/52190354 本文介绍CentOS 6.3从自带的Pyhon版本是2.6升级到2.7.6的方法 ...
- (纪录片)鸟瞰中国 China from Above
简介: 类型: 纪录片官方网站: natgeotv.com/uk/china-from-above制片国家/地区: 美国语言: 英语集数: 2单集片长: 44分钟IMDb链接: tt4872012 主 ...
- Linux中10个有用的命令行补齐命令
本文转自GeekFan,感觉确实比较极客范啊,[TAB][TAB]补全都知道,但是你知道可以定制化补全吗? ---------------------------------------------- ...
- ZH奶酪:PHP error_log()将错误信息写入日志文件
error_log() 是发送错误信息到某个地方的一个函数,在程序编程中比较常见,尤其是在程序调试阶段. bool error_log ( string $message [, int $messag ...
- 关于RF对于不在屏幕内的页面元素的处理办法
1.碰到的问题: 最近在公司用Robot framework+Selenium2Library做项目,碰到部分页面比较长,无法完全显示在屏幕内,需要上下滚动滚动条才能看到下半部分的页面元素.于是呼,问 ...
- HDS推出HUS中端阵列 文件、块和对象统一存储
http://storage.chinabyte.com/86/12320086.shtml http://storage.chinabyte.com/134/12324134.shtml 日立数据系 ...
- MySql 常见错误代码大全
B.. 服务器错误代码和消息 服务器错误信息来自下述源文件: · 错误消息信息列在share/errmsg.txt文件中.“%d”和“%s”分别代表编号和字符串,显示时,它们将被消息值取代. · 错误 ...
- python之tcp自动重连
操作系统: CentOS 6.9_x64 python语言版本: 2.7.13 问题描述 现有一个tcp客户端程序,需定期从服务器取数据,但由于种种原因(网络不稳定等)需要自动重连. 测试服务器示例代 ...