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 ...
随机推荐
- Mongoose的分页功能
来自: https://github.com/edwardhotchkiss/mongoose-paginate 拷贝如下: Note: This plugin will only work wi ...
- Hibernate: No Session found for current thread
在Struts2+Hibernate+Srping项目中经常会遇到这种问题 我知道的一种情况是: Spring的事务配置中没有配置好异常出现处的路径 <aop:advisor pointcut= ...
- 一道Javascript面试题引发的血案
文章首发于szhshp的第三边境研究所,转载请注明 先来看几道面试题,公司的开发们都尝试做了一下,然而基本没有人能够全部答对. 覆盖的考点很多,也有一些难度,题目挺有意思建议手动执行一边玩玩. Que ...
- Apache Kafka学习 (一)
前言:最近公司开始要研究大数据的消息记录,于是开始研究kafka. 市面上kafka的书很少,有的也版本比较落后,于是仗着自己英文还不错,上官网直接学习. ^_^ 1. 开始 - 基本概念 学习一样东 ...
- python网络爬虫 - 如何伪装逃过反爬虫程序
有的时候,我们本来写得好好的爬虫代码,之前还运行得Ok, 一下子突然报错了. 报错信息如下: Http 800 Internal internet error 这是因为你的对象网站设置了反爬虫程序,如 ...
- Mysql5.7初始化成空密码或随机密码的方式
命令在此:mysqld --initialize-insecure --user=mysql 文档表明,使用-initialize生成随机密码,使用-initialize-insecure生成空密码. ...
- Go语言中Path包用法
// path package main import ( "fmt" "os" "path" "path/filepath&qu ...
- cpu内存访问速度,磁盘和网络速度,所有人都应该知道的数字
google 工程师Jeff Dean 首先在他关于分布式系统的ppt文档列出来的,到处被引用的很多. 1纳秒等于10亿分之一秒,= 10 ^ -9 秒 ---------------------- ...
- 使用Flask+MongoDB实现基于REST的接口简单操作
目录 前言 1 准备工作 2 具体实现 前言 最近在捣鼓如何使用阿里云服务器搭建一个简单的基于Flask框架的后端接口,刚开始为了图方便,就直接买了一个Windows Server 2008系统服务器 ...
- J2EE用监听器实现同一用户只能有一个在线
这里我们讨论的是已登陆或将要登陆的用户,游客不在讨论的范围之内.这一点大家应该很容易就能理解的吧. 那么我们应该怎样去实现同一用户只能有一个在线这样的一个小功能呢? 有人 ...