标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
//1085422276 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<bitset> #include<set> #include<vector> using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,127,sizeof(a)); #define memfy(a) memset(a,-1,sizeof(a)) #define TS printf("111111\n"); #define FOR(i,a,b) for( int i=a;i<=b;i++) #define FORJ(i,a,b) for(int i=a;i>=b;i--) #define READ(a,b) scanf("%d%d",&a,&b) #define mod 1000000007 #define maxn 100000+5 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘) { if(ch==‘-‘)f=-1; ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘; ch=getchar(); } return x*f; } //**************************************** int n,m; double dp[maxn]; int ne[maxn]; int main() { while(READ(n,m)!=EOF) { mem(dp);memfy(ne); int x,y; if(n==0&&m==0)break; FOR(i,1,m) { scanf("%d%d",&x,&y); ne[x]=y; } FORJ(i,n-1,0) { if(ne[i]!=-1)dp[i]=dp[ne[i]]; else { FOR(l,1,6)dp[i]+=(dp[i+l]/6.0); dp[i]+=1.0; } } printf("%.4f\n",dp[0]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4811055.html