Robot

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 779    Accepted Submission(s): 304

Problem Description
Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise.

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.

 
Input
There are multiple test cases. 
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.
 
Output
For each test case in the input, you should output a line with the expected possibility. Output should be round to 4 digits after decimal points.
 
Sample Input
3 1 1 2
1
5 2 4 4
1
2
0 0 0 0
 
Sample Output
0.5000
0.2500
 
Source
 

题意:给你一个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 (概率 & 期望)的更多相关文章

  1. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  2. HDU 4576 Robot (概率DP)

    暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...

  3. HDU 4576 Robot (很水的概率题)

    Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Sub ...

  4. HDU 4576 Robot(概率dp)

    Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Sub ...

  5. HDU - 4576 Robot(概率dp+滚动数组)

    题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1. ...

  6. HDU 4576 简单概率 + 滚动数组DP(大坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 坑大发了,居然加 % 也会超时: #include <cstdio> #includ ...

  7. HDU 4576 Robot

    思路 概率dp 既然是求概率,顺推 显然有转移\(dp[i][j]=dp[i-1][j-w]/2+dp[i-1][w]/2\) 然后是环,注意特判一下 环上不要用取模处理循环的情况,会被卡常 代码 # ...

  8. hdu 4576(简单概率dp | 矩阵优化)

    艰难的一道题,体现出菜菜的我... 首先,先吐槽下. 这题到底出题人是怎么想的,用普通概率dp水过??? 那为什么我概率dp写的稍微烂点就一直tle?  感觉很不公平.大家算法都一致,因为我程序没有那 ...

  9. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

随机推荐

  1. 1418 This function has none of DETERMINISTIC,NO SQL,or R

    标签: [err]1418 函数创建报错 分类: 菜鸟DBA之MySQL --------------------------------------------------------------- ...

  2. C#.NET常见问题(FAQ)-如何把文本复制粘贴到文本框的光标位置

    前面已经通过Clipborad.SetText之后,这里就要先把目标文本框的文本改成插入之后的值,然后修改光标所在位置  

  3. SQL从一个表查询数据插入/更新到另一个表

    示例一: 从数据库表A中查询出数据插入到数据库表B 从数据库DataBaseA的表TDA中查询出数据插入到数据库DataBaseB的表TDB insert into [DataBaseA].[dbo] ...

  4. PetaPoco使用

    <?xml version="1.0" encoding="utf-8" ?> <configuration> <connecti ...

  5. 转:nginx基础概念(keepalive、pipe)

    keapalive 当然,在nginx中,对于http1.0与http1.1也是支持长连接的.什么是长连接呢?我们知道,http请求是基于TCP协议之上的,那么,当客户端在发起请求前,需要先与服务端建 ...

  6. Java Netty (1)

    Netty是由JBOSS提供的一个java开源框架,本质上也是NIO,是对NIO的封装,比NIO更加高级,功能更加强大.可以说发展的路线是IO->NIO->Netty. ServerBoo ...

  7. Webwork【08】结合实战简析Controller 配置

    虽然现在 MVC 框架层出不穷,但做为 Struts 前身的 webwork. 其经典程度不亚于贝利之于足球,双 11 之于淘宝特卖. 本篇将结合 webwork controller 配置文件 xw ...

  8. sqlserver 表中记录生成insert,可以加条件,可以生成建表语句

    sqlserver 表中记录生成insert,可以加条件,可以生成建表语句 create PROCEDURE [sp_getinsert] ( ) , --如果非默认架构,可以加上架构名 例如:sch ...

  9. Centos 7 文件和目录管理

    查看权限在终端输入:  ls -l xxx.xxx (xxx.xxx是文件名)  那么就会出现相类似的信息,主要都是这些:  -rw-rw-r--  其中: 最前面那个 - 代表的是类型      中 ...

  10. 微软Xbox One无线手柄控制机器人

    ROS中的joy包提供了游戏手柄的驱动,并且包含joy_node节点,这一节点可以发布包含手柄按钮和轴信息的Joy消息.在终端中输入下面命令,安装joy包: $ sudo apt-get instal ...