题目大意:问从0到n所花费时间平均时间。每次有投骰子,投到几就走几步。原题还有坐飞机
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
typedef long long ll;
const int inf=0x3f3f3f3f;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define FFor(i,a,b) for(int i=a;i>=b;i--)
template <class T> inline T min(T a,T b,T c)
{
return min(min(a,b),c);
}
template <class T> inline T max(T a,T b,T c)
{
return max(max(a,b),c);
}
template <class T> inline T min(T a,T b,T c,T d)
{
return min(min(a,b),min(c,d));
}
template <class T> inline T max(T a,T b,T c,T d)
{
return max(max(a,b),max(c,d));
}
using namespace std;
const int N=1e5+;
const double eps=1e-;
//***********name**************
double f[N];
int n,m;
int trans[N];
//***********function********** //******************************
int main()
{
// freopen("test.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==)break;
memset(f,,sizeof(f));
memset(trans,,sizeof(trans));
int a,b;
For(i,,m)
{
scanf("%d%d",&a,&b);
trans[a]=b;
}
f[n]=;
FFor(i,n-,)
if(trans[i])
f[i]=f[trans[i]];
else
{
For(j,,)
f[i]+=f[i+j];
f[i]/=;
f[i]+=;
} printf("%.4f\n",f[]);
} return ;
}