【HDU4405】【Aeroplane chess】【概率dp】
来源:互联网 发布:远程监控域名 编辑:程序博客网 时间:2024/06/08 07:45
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2490 Accepted Submission(s): 1604
Problem Description
Hzz 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 have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). When Hzz is at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.
There are 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 that there is no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
There are 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 that there is no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
Input
There are multiple test cases.
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).
The input end with N=0, M=0.
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).
The input end with N=0, M=0.
Output
For each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to 4 digits after decimal point.
Sample Input
2 08 32 44 57 80 0
Sample Output
1.16672.3441
Source
2012 ACM/ICPC Asia Regional Jinhua Online
Recommend
zhoujiaqi2010 | We have carefully selected several similar problems for you: 5395 5394 5393 5392 5391
#include <iostream>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <cstdlib>#include <cstdio>#include <algorithm>using namespace std;int n,m;struct Edge{int s,e;}edge[1010];int to[100100];double dp[100100];int cmp(const Edge&x, const Edge&y){if(x.e == y.e)return x.s > y.s;return x.e > y.e;}int main(){ while(scanf("%d%d",&n,&m)){if(n==0 && m==0) break;memset(dp,0,sizeof(dp));for(int i=0;i<m;i++){scanf("%d%d",&edge[i].s,&edge[i].e);}for(int i=1;i<=n+10;i++) to[i] = i;sort(edge,edge+m,cmp);for(int i=0;i<m;i++){Edge eg = edge[i];to[eg.s] = to[eg.e];}for(int i=n-1;i>=0;i--){dp[i] = 1;for(int k=1;k<=6;k++){dp[i] += 1.0/6.0 * dp[to[i+k]];}}printf("%.4lf\n",dp[0]);} return 0;}
0 0
- hdu4405 Aeroplane chess (概率dp)
- HDU4405--Aeroplane chess--概率DP
- 【HDU4405】【Aeroplane chess】【概率dp】
- hdu4405--Aeroplane chess+概率期望dp
- HDU4405 Aeroplane chess (概率DP求期望)
- hdu4405 Aeroplane chess【概率DP+期望问题】
- HDU4405:Aeroplane chess(概率dp & 期望)
- HDU4405-Aeroplane chess(概率DP求期望)
- hdu4405[Aeroplane chess] 有点懂了期望概率DP
- hdu4405 Aeroplane chess 【期望dp】
- 【期望DP】HDU4405 Aeroplane chess
- hdu4405 Aeroplane chess(期望dp)
- hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)
- HDU4405 Aeroplane chess
- hdu4405 Aeroplane chess 期望
- hdu4405 Aeroplane chess
- HDU4405 Aeroplane chess
- HDU4405-Aeroplane chess
- ViewPager+Fragment+RadioGruop实现滑动效果
- 在被管理中体会管理的难!
- SingleTon
- Codeforces Round #316 (Div. 2) D. Tree Requests (DFS序)
- Leetcode#53||Maximum Subarray
- 【HDU4405】【Aeroplane chess】【概率dp】
- Ubiquitous Religions
- Jedis主从切换实现
- 1. JavaScript Array 对象
- HDU1023 Train Problem II【Catalan数】
- CLRS第五章思考题
- table表格td撑开
- HDU 2473 并查集的删点
- Android 禁止横竖屏切换,onConfigurationChanged的作用