HDU 4576 Robot

Robot

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

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

2013ACM-ICPC杭州赛区全国邀请赛

解题:dp。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define pii pair<int,int>
15 #define INF 0x3f3f3f3f
16 using namespace std;
17 double dp[2][210];
18 int main() {
19     int n,m,l,r,tmp,i,cur;
20     double ans = 0.0;
21     while(scanf("%d %d %d %d",&n,&m,&l,&r),n||m||l||r){
22         dp[0][0] = 1;
23         for(int i = 1; i < n; i++) dp[0][i] = 0;
24         cur = 0;
25         while(m--){
26             scanf("%d",&tmp);
27             for(i = 0; i < n; i++)
28                 dp[cur^1][i] = 0.5*dp[cur][(i-tmp+n)%n] + 0.5*dp[cur][(i+tmp)%n];
29             cur ^= 1;
30         }
31         ans = 0;
32         for(i = l-1; i < r; i++)
33             ans += dp[cur][i];
34         printf("%.4f\n",ans);
35     }
36     return 0;
37 }

时间: 2024-10-10 10:34:09

HDU 4576 Robot的相关文章

[ACM] HDU 4576 Robot (概率DP,滚动数组)

Robot 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 ro

HDU 4576 Robot(概率题)

Robot 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 ro

HDU 4576 Robot 概率DP 水题

Robot Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 3851    Accepted Submission(s): 1246 Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells.

HDU 4576 Robot(概率dp)

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.

HDU 4576 Robot (概率DP)

题意: 思路: #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; double dp[3][300]; int main() { int n,m; int l,r; int i,j,k; double ans; int temp,now; while(scanf("%d%d%d%d",&n,&

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

题意:所有的格子围成一个圈,标号为1~n,若从格子1出发,每次指令告知行走的步数,但可能逆时针也可能顺时针走,概率都是1/2,那么问走了m次指令后位于格子l~r(1≤l≤r≤n)的概率. 分析: 1.因为m次指令后不知道会走到哪,会有很多种可能,但是知道从哪里出发,所以起始状态是已知的,在最初的状态,位于格子1是必然的,概率为1. 2.本题应用滚动数组,因为每次指令后都会延伸出无数种可能,这些可能是在前一种状态的基础上延伸的,而且延伸过后前一种状态的值不再有意义,完全可以被当前状态所覆盖. 3.

HDU 1035 Robot Motion Union Find 并查集题解

本题的类型我一看就想到使用并查集解了,因为要查找是否有环,这是并查集的典型用法. 但是由于本题数据实在是太水了,故此有人使用直接模拟都过了.这让本题降了个档次. 这里使用并查集解.而且可以根据需要简化并查集函数,代码还是很好打的. #include <stdio.h> #include <vector> #include <string.h> #include <algorithm> #include <iostream> #include &l

HDU 4576

http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给一个1-n的环,m次操作,每次操作顺时针或逆时针走w步,求最后落在[l,r]区间的概率 dp[i][j]表示第i步走到点j的概率,很裸的概率dp,i太大,需要滚动数组 时限4s,我的代码3984ms过的,有点悬 #include <iostream> #include <cstdio> #include <cstring> #include <cmath>

hdu 4593 Robot

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4593 Robot Description A robot is a mechanical or virtual artificial agent, usually an electro-mechanical machine that is guided by a computer program or electronic circuitry. Robots can be autonomous or