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 ...
随机推荐
- SSAS知识回放之订单数据分析
1:目标 基于已经做好的DW,利用SSAS实现一个多维数据模型的创建,通过浏览可以简单的实现订单数据的分析 2:步骤 2.1:添加数据源 如下图所示,创建一个数据仓库层的数据源连接 2.2:添加数据源 ...
- The application was unable to start correctly (0xc000007b)
用VS2013建立了一个c++ console application,然后引用了一个DLL, 启动的时候报错: The application was unable to start correct ...
- ExtMail telnet 25端口号 不通
搭建好的Mail服务器在本地端口号25是开的,但是在别的电脑上就连不上. 修改/etc/postfix/main.cf文件,将 inet_interfaces = localhost 注释掉即可.
- ionic3+angular5页面间传递参数
一.从一个页面跳转到另一个页面的方法 1.引入服务 import { NavController } from 'ionic-angular'; 2.初始化 constructor(public na ...
- uni - 自定义组件
目录结构如下 点击下载自定义组件示例
- 排序基础之插入排序、冒泡排序、选择排序详解与Java代码实现
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6594533.html 一:插入排序==逐个往前相邻数比较交换,小的在前 第一轮:A[1]与A[0]比较,小的 ...
- cocos2d-js 粒子系统使用自定义图片,还原原来的图片宽高
粒子系统使用自定义图片很简单只需要在plist最后一行设置png的名称即可.但是,在实际使用中,发现自定义图片无法使用原来的形状,例如设置了一长条的图片,结果出来确实一个个圆球. 翻了plist和cc ...
- 〖Linux〗在tmux同时使用bash和zsh
个人有两份tmux配置文件: ~/.tmux.conf # 使用zsh,主要是日常使用,zsh太好使用了 ~/.tmux.conf.bash # 使用bash,主要是Android编译使用 按照tmu ...
- JUC-线程八锁
1,一个对象里面如果有多个synchronized方法,某一个时刻内,只要一个线程去调用其中的一个synchronized方法了,其它的线程都只能等待, 换句话说,某一个时刻内,只能有唯一一个线程去访 ...
- Mysql 将结果保存到文件 从文件里运行sql语句 记录操作过程(tee 命令的使用)
1. 有时候我们可能须要记录我们对mysql的操作过程,这时我们能够使用mysql的tee命令 1)第一种情况是在链接数据库的时候使用tee >mysql -u root -p --te ...