#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <list>
#include <stack>
#include <limits>
#include <deque>
#include <algorithm>
#include <functional>
using namespace std;
#define PF(x) (scanf("%d",&x))
#define PT(x,y) (scanf("%d%d",&x,&y))
#define PB(x) (scanf("%I64d",&x))
#define PR(x) (printf("%d\n",(x)))
#define PRB(x) (printf("I64d\n",(x)))
#define PRT(x,y) (scanf("%d %d\n",(x),(y))
#define Min(x,y) ( (x)>(y)?(y):(x) )
#define Max(x,y) ( (x)>(y)?(x):(y) )
#define PE(x) while(scanf("%d",&x)!=EOF)
#define L(x) x<<1
#define Mid(x,y) ( (x) + (y) ) >>1
#define R(x) ((x)<<1 |1 )
#define For(i,n) for(int i=0;i<n;i++)
#define RFor(i,s,n) for(int i=s;i<(n);i++)
#define N 1000500
#define M 100
#define Mod 1000
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
typedef __int64 LL;
int n,m;
int fa[N];
double ar[N];
double arr[N];
double q(int i)
{
if(i<0) return 0;
return ar[i];
}
double rq(int i)
{
if(i<0) return 0;
return arr[i];
}
int is(int i)
{
if(i<0) return 1;
if(fa[i] == -1) return 1;
return 0;
}
void solve()
{
memset(ar,0,sizeof(ar));
memset(arr,0,sizeof(arr));
double s=0;
ar[0] = 1;arr[0]=0;
for(int i=1;i<=n+5;i++)
{
if(i>n)
{
double res = ar[i];
for(int j=1;j<=6;j++)
if(i-j<n && is(i-j)) ar[i] += q(i-j)/6,arr[i] += rq(i-j)/6;
arr[i] += ar[i];arr[i]-=res;
}
else
{
double res = ar[i];
for(int j=1;j<=6;j++)
if(is(i-j))
ar[i] += q(i-j)/6,arr[i] += rq(i-j)/6;
arr[i] += ar[i];
arr[i] -= res;
}
if(fa[i] != -1)
{
int t = i;
while(fa[t] != -1) t = fa[t];
ar[t] += ar[i];
arr[t] += arr[i];
}
}
for(int i=n;i<=n+5;i++) s += arr[i];
printf("%.4lf\n",s);
}
void init()
{
while(true)
{
PT(n,m);
if(n ==0 && m==0) break;
memset(fa,-1,sizeof(fa));
For(i,m)
{
int a,b;
PT(a,b);
fa[a] = b;
}
solve();
}
}
int main()
{
init();
return 0;
}
2012 ACM/ICPC 金华赛区邀请赛1006
最新推荐文章于 2018-09-20 09:40:31 发布