Robot

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

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

分析

code

 #include<cstdio>
#include<algorithm>
#include<cstring> using namespace std; double f[][];
// f[i][j]到第i次操作,位置j上的概率 int main() { int n,m,l,r;
while (~scanf("%d%d%d%d",&n,&m,&l,&r) && n+m+l+r) {
memset(f,,sizeof(f));
f[][] = 1.0;
int cur = ;
for (int w,i=; i<=m; ++i) {
scanf("%d",&w);
w = w%n;
cur = cur^;
for (int k=; k<=n; ++k) {
f[cur][k] = f[cur^][k+w>n?k+w-n:k+w]/2.0 + f[cur^][k-w<?k-w+n:k-w]/2.0;
}
}
double ans = 0.0;
for (int i=l; i<=r; ++i) ans += f[cur][i];
printf("%.4lf\n",ans);
}
return ;
}

最新文章

  1. 【转】MySql中的函数
  2. 关于react native
  3. MSDN Kinect for Windows SDK中文版论坛开放了
  4. 根据不同的实体及其ID来获取数据库中的数据
  5. 使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法
  6. Quartzs -- Quartz.properties 配置
  7. codeforces 192a
  8. Cocos2d-x之Touch事件处理机制
  9. Tomcat 服务器的端口号的修改
  10. java 写文件解析
  11. JavaScript window.setTimeout() 的详细用法
  12. 解决NSURLConnection finished with error - code -1100错误
  13. 【总结】Java异常分类
  14. JS中的可枚举属性与不可枚举属性以及扩展
  15. QQ群成员发言次数统计(正则表达式版)
  16. 阅读Google Protocol Buffers 指南,整理pb语法
  17. 08 IO库
  18. Datetime 24小时制
  19. java中的安全模型(沙箱机制)
  20. 【C++】数组-整数从大到小排序

热门文章

  1. sharepoint知识点总结
  2. Azure 5 月新公布(二)
  3. 五环之歌之PHP分页
  4. 快速提取邮箱地址(利用word或网站)
  5. MySQL一致性非锁定读
  6. Android(java)学习笔记64:Android权限大全
  7. 【转】Druid连接池一个设置引发的血案
  8. 第十五章 函数————函数的递归、生成器send 、匿名函数
  9. cutil.h问题
  10. 总结ing