fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. double a[101][101][101];
  5. int n;
  6.  
  7. int u[] = {-2,-2,2,2,-1,-1,1,1};
  8. int v[] = {-1,1,1,-1,2,-2,2,-2};
  9.  
  10. int main() {
  11. int t,x,y,i,j,k,z,l;
  12. cin>>t;
  13. double d;
  14. while(t--){
  15. d = 0;
  16. cin>>n>>x>>y>>z;
  17. if(k == 0){
  18. cout<<1<<endl;
  19. continue;
  20. }
  21. for(i=0;i<n;i++){
  22. for(j=0;j<n;j++)
  23. for(k=0;k<=z;k++)
  24. a[i][j][k] = 0;
  25. }
  26. a[x][y][0] = 1;
  27. for(k=0;k<z;k++){
  28. for(i=0;i<n;i++){
  29. for(j=0;j<n;j++){
  30. for(l=0;l<8;l++)
  31. if(u[l]+i < n and u[l]+i >= 0 and
  32. v[l]+j < n and v[l]+j >= 0)
  33. a[u[l]+i][v[l]+j][k+1] += (1/8.0)*a[i][j][k];
  34. }
  35. }
  36. }
  37. for(i=0;i<n;i++)
  38. for(j=0;j<n;j++)
  39. d += a[i][j][z];
  40. printf("%.6lf\n",d);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 23280KB
stdin
1
8 0 0 3
stdout
1