Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:我的程序为什么是错的呀?哪位牛人帮忙看下!!In Reply To:我的程序为什么是错的呀?哪位牛人帮忙看下!! Posted by:scuxy at 2008-03-12 14:46:50 > #include<stdio.h> > #include<memory.h> > double p[102][102]; > int l[102],b[102]; > int main() > { > int n,t,ll,bb; > while(scanf("%d%d%d%d",&n,&t,&ll,&bb)==4) > { > int i,j,k; > memset(p,0,sizeof(p)); > memset(l,0,sizeof(l)); > memset(b,0,sizeof(b)); > for(i=0;i<ll;i++) > { > scanf("%d",&k); > l[k]=1; > } > for(j=0;j<bb;j++) > { > scanf("%d",&k); > b[k]=1; > } > p[0][0]=1.0; > double re=0.0; > for(i=1;i<=t;i++) > { > for(j=1;j<=n;j++) > { > int w; > w=j; > if(b[j]==1) > w=0; > for(k=j-1;k>=j-6&&k>=0;k--) > { > > p[i][w]=p[i][w]+p[i-1][k]/6.0; > } > if(j!=n) > { > for(k=2*n-6-j;k<=n&&n-k<6;k++) > p[i][w]=p[i][w]+p[i-1][k]/6.0; > } > if(l[j]==1) > { > p[i+1][w]=p[i+1][w]+p[i][w]/6.0;// > } > } > re=re+p[i][n]; > } > printf("%.6lf\n",re); > } > return 0; > } > > > 比如说当骰子在第1步到了n时,下一步n位置的骰子就不能考虑了。 也就是说for(j=1;j<=n;j++) 应该到n-1 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator