HDU 4576 Robot

Source: Internet
Author: User
Robot

Time Limit: 8000/4000 MS (Java/others) memory limit: 102400/102400 K (Java/Others)
Total submission (s): 2776 accepted submission (s): 948


Problem descriptionMichael 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.

 

InputThere 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 shoshould not process this test case.

 

OutputFor each test case in the input, you should output a line with the expected possibility. Output shocould be round to 4 digits after decimal points.

 

Sample input 3 1 215 2 4 4120 0 0 0

 

Sample output0.50000.2500

 

Source2013ACM-ICPC Hangzhou Division national invitational Competition

Problem solving: 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 long14 #define pii pair<int,int>15 #define INF 0x3f3f3f3f16 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 }
View code

 

HDU 4576 Robot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.