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. 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杭州赛区全国邀请赛

题意:给出一个环,上面分成n个区域,分别编号为1~n,有一个指针,刚开始的时候指向1的位置

现在有m个操作,每一个操作输入一个w,指针转动w个单位,顺时针转,和逆时针转的概率都是0.5,

现在问m个操作后,指针指向区间[l,r]的概率是多少

dp[i][j]表示第i个命令后,指针指向区域j的概率

这里命令数m很大,而我们递推的时候只需要保存前面一个的状态,所以i%2,节省空间。

 1 #include<cstdio>
 2 #include<cstring>
 3
 4 using namespace std;
 5
 6 double dp[2][210];
 7
 8 int main()
 9 {
10     int n,m,l,r;
11     while(scanf("%d%d%d%d",&n,&m,&l,&r))
12     {
13         if(!n&&!m&&!l&&!r)
14             break;
15         memset(dp,0,sizeof dp);
16         dp[0][1]=1.0;
17         int w;
18         int a,b;
19         for(int i=1;i<=m;i++)
20         {
21             scanf("%d",&w);
22             for(int j=1;j<=n;j++)
23             {
24                 a=j-w;
25                 if(a<1)
26                     a+=n;
27                 b=j+w;
28                 if(b>n)
29                     b-=n;
30                 dp[i%2][j]=dp[(i-1)%2][a]*0.5+dp[(i-1)%2][b]*0.5;
31             }
32         }
33         double ans=0.0;
34         int mm=m%2;
35         for(int i=l;i<=r;i++)
36             ans+=dp[mm][i];
37
38         printf("%.4f\n",ans);
39     }
40     return 0;
41 }

时间: 2024-11-03 21:57:35

HDU 4576 Robot 概率DP 水题的相关文章

Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃圾,大哥拿来了一袋老鼠,其中有w只白老鼠和b只黑老鼠.胡小兔先抓,先抓到白老鼠的人赢. 每次学姐抓完老鼠之后,总会有另外一只老鼠从袋子里自己跑出来(这只老鼠不算任何人抓的),而胡小兔抓老鼠时则不会发生这样的事. 每次袋子里的每只老鼠被抓到的概率相等,当有一只老鼠跑出来的时候,每只老鼠跑出来的几率也相

hdu 5001 walk 概率dp入门题

Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel t

13年山东省赛 The number of steps(概率dp水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Memory Limit: 128 M Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two ro

HDU 4089 Activation (概率dp 好题 + 难题)

Activation Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1842    Accepted Submission(s): 689 Problem Description After 4 years' waiting, the game "Chinese Paladin 5" finally comes out.

HDU 4035 Maze 概率DP 好题

Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2012    Accepted Submission(s): 802Special Judge Problem Description When wake up, lxhgww find himself in a huge maze. The maze consisted by

LightOJ1030 Discovering Gold 概率DP 水题

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1.

hdu3722Card Game 概率dp水题

//3中天气前一天天气为i转为第二天天气为j的概率为p[i][j] //问第一天天气为i,n天后天气为j的概率 //dp[i][j][k]在第一天天气为j的情况下第n天的天气为j的概率 //dp[i][j][k] += dp[i-1][j][s]*dp[1][s][k] ; #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 1010 ;

HDU 4405 Aeroplane chess 概率DP 水题

Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2327    Accepted Submission(s): 1512 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids lab

hdu 4405(概率dp简单题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1535    Accepted Submission(s): 1050 Problem Description Hzz loves aeroplane