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:WA了无数次,终于搞懂错在哪了,不是double的问题,加了几句后就AC了In Reply To:WA了无数次,终于搞懂错在哪了,不是double的问题,加了几句后就AC了 Posted by:x1e398u at 2005-11-06 10:44:50 好象没有考虑高精度的问题 > #include <iostream.H> > #include <math.h> > > int main() > { > int k,n,i,j; > double d[10][100]; > for(k=0;k<10;k++) > d[k][0]=1; > while(cin>>k>>n) > { > /* if(k==0) > { > cout<<"100.00000\n"; > continue; > }此段若不加就总WA,测试了一下,若不加则输入0,100后程序直接退出*/ > for(i=1;i<n;i++) > for(j=0;j<=k;j++) > if(!j) d[j][i]=d[j][i-1]+d[j+1][i-1]; > else if(j==k) d[j][i]=d[j][i-1]+d[j-1][i-1]; > else d[j][i]=d[j-1][i-1]+d[j][i-1]+d[j+1][i-1]; > double sum=0; > for(i=0;i<=k;i++) > sum+=d[i][n-1]; > sum*=100; > sum/=pow(k+1,n); > cout.setf(ios::fixed); > cout.precision(5); > cout<<sum<<endl; > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator