Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4454 Accepted Submission(s): 2809
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.
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.
2 0 8 3 2 4 4 5 7 8 0 0
1.1667 2.3441
#include<stdio.h>
#include<cstring>
#define clear(a) memset(a, 0, sizeof(a))
#define Mercer register int
const int maxn = 100005;
double dp[maxn];
int vis[maxn], x, y, n, m;
inline const int read(){
register int x = 0;
register char ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
while(ch >= '0' && ch <= '9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();
return x;
}
int main(){
while(n = read() ,m = read(), n || m){
clear(dp), clear(vis);
for(Mercer i = 1; i <= m; ++i) x = read(), y = read(), vis[x] = y;
for(int i = n - 1; ~i; --i)
if(!vis[i])
for(int j = 1; j <= 6; ++j)
dp[i] += (dp[i+j] + 1) / 6.0;
else dp[i] = dp[vis[i]];
printf("%.4f\n", dp[0]);
}
}
1329




被折叠的 条评论
为什么被折叠?



