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. linux ps 命令的查看

    linux ps 命令的结果中VSZ,RSS,STAT的含义和大小 ps是linux系统的进程管理工具,相当于windows中的资源管理器的一部分功能. 一般来说,ps aux命令执行结果的几个列的信 ...

  2. HTTP协议中源端口和目标端口的问题

    [提问] How is source port for HTTP determined? Is there ever collision in NAT?   I know that when a HT ...

  3. 文档的js

    /* 主站,子频道,定向站点共用 */ (function() { scrollToAnchor(); toggleSearchForm(); scrollTop(); initScrollBar() ...

  4. ASP入门(二十一)- 如何自己获取 ADO 连接字符串

    1.新建一个文本文件,并将文件名修改为[ado.udl] 注意 如果不显示扩展名,请在资源管理器的[查看 | 选项]对话框中去掉"隐藏已知文件类型的扩展名"勾就可以了. 2.双击这 ...

  5. [Canvas]首个小游戏告成

    英雄在地图上射箭杀怪兽,杀完了就胜利了. 点此下载程序试玩. 图例: 代码: <!DOCTYPE html> <html lang="utf-8"> < ...

  6. ext js/Ext.Net_演示 htmleditor 上传&插入图片

    本文内容 解决方案结构 HtmlEditor_Upload.js 脚本 HtmlEditorUploadImg.ashx 上传图片到服务器 演示 htmleditor 控件添加插入图片功能   解决方 ...

  7. 彻底解决 Intellij IDEA 卡顿 优化笔记,重要的快捷键

    由于工作中经常出现分支各种切换,使用Eclipse便不再像以前那么舒服了,不停的修改工作空间,每次修改完工作空间又是一堆一堆的个性化设置,来回的切换,真的很累.我们做软件的,怎么能不去尝试新鲜的呢,毕 ...

  8. Python 使用pymongo操作mongodb库

    Python 使用pymongo操作mongodb库 2016-12-31 21:55 1115人阅读 评论(0) 收藏 举报  分类: - - - Python(10)  版权声明:本文为博主原创文 ...

  9. 用一条sql取得第10到第20条的记录-Mssql数据库

    因为id可能不是连续的,所以不能用取得10<id<20的记录的方法. 有三种方法可以实现: 一.搜索前20条记录,指定不包括前10条 语句: select top 20 * from tb ...

  10. setTimeout迭代替换setInterval

    一.它们之间的区别 setTimeout - 仅执行一次 setInterval - 间隔执行     二.为什么推荐用setTimeout替换掉setIntelval?   javascript是异 ...