HDU 4405 aeroplane Chess probability DP Water problem

Source: Internet
Author: User

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 DescriptionHzz loves aeroplane chess very much. The chess map contains n+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice (a dice has six faces with equal probability to face up and the numbers on the faces is 1, 2,3,4,5,6). When Hzz was at grid I and the dice number is x, he would moves to grid i+x. Hzz finishes the game when I+x is E Qual to or greater than N.

There is also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<xi<yi<=n) without throwing the dice. If There is another flight line from Yi, Hzz can take the flight line continuously. It is granted this there is no, or more flight lines start from the same grid.

Hzz calculate the expected dice throwing times to finish the game. 

InputThere is multiple test cases.
Each test case contains several lines.
The first line contains the integers N (1≤n≤100000) and M (0≤m≤1000).
Then M. lines follow, each line contains the integers xi,yi (1≤xi<yi≤n).
the input end with n=0, m=0. 

Outputfor each test case in the input, you should output a line indicating the expected dice throwing times. Output should is rounded to 4 digits after decimal point. 

Sample Input2 08 3244 57 80 0 

Sample Output1.16672.3441 

SourceACM/ICPC Asia Regional Jinhua OnlineTest Instructions:play a flying chess, there is a row of lattice, n+1, numbered 0~n,now the plane departs from 0, which specifies that when the plane arrives at >=n, the plane arrives at its destination. each time the plane to fly, shake a dice, dice number of the number of forward lattice,In addition, the lattice has many channels, when the plane reaches u, it can be changed directly to V (U<V) (this is a psychic)ask the number of times the plane has to arrive at its destination from 0 (that is, the number of roll dice)Dp[i] Indicates the number of times a plane needs to fly from lattice I to its destination.
1#include <cstdio>2#include <cstring>3 4 using namespacestd;5 6 Const intmaxn=1e5+Ten;7 Const intmaxm=1e3+Ten;8 Const Double Base=1.0/6.0;9 Ten DoubleDP[MAXN]; One intJUMP[MAXN]; A  - DoubleConintx) - { the     Doubleres=0.0; -      for(inti=x;i<=x+5; i++) -res+=Dp[i]; -     returnRes; + } -  + intMain () A { at     intn,m; -      while(SCANF ("%d%d",&n,&m)) -     { -         if(!n&&!m) -              Break; -memset (Jump,0,sizeof(jump)); in          for(intI=0; i<m;i++) -         { to             intu,v; +scanf"%d%d",&u,&v); -jump[u]=v; the         } *Memset (DP,0,sizeofDP); $          for(inti=n-1; i>=0; i--)Panax Notoginseng         { -             if(Jump[i]) thedp[i]=Dp[jump[i]]; +             Else Adp[i]=Base*con (i+1)+1; the         } +printf"%.4f\n", dp[0]); -     } $     return 0; $}
View Code

HDU 4405 aeroplane Chess probability DP Water problem

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.