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