-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathhdu4405.cpp
41 lines (40 loc) · 888 Bytes
/
hdu4405.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
double e[100100];
int f[100100];
int main()
{
int n, m;
while(scanf("%d%d", &n, &m) != EOF && (n != 0 || m != 0))
{
for(int i = 0; i <= n; i++)
e[i] = 0;
memset(f, -1, sizeof(f));
for(int i = 0; i < m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
f[a] = b;
}
for(int i = n - 1; i >= 0; i--)
{
if(f[i] != -1) e[i] = e[f[i]];
else
{
for(int j = 1; j <= 6; j++)
{
if(i + j <= n) e[i] += (1.0 / 6) * e[i + j];
}
e[i] += 1.0;
}
}
printf("%.4lf\n", e[0]);
}
return 0;
}