fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 2;
  5.  
  6. struct matrix
  7. {
  8. double x[N+1][N+1];
  9. matrix(){memset(x, 0, sizeof(x));}
  10. matrix(double init)
  11. {
  12. memset(x, 0, sizeof(x));
  13. for(int i = 1; i <= N; i++)
  14. x[i][i] = init;
  15. }
  16. matrix operator *(matrix that)
  17. {
  18. matrix ret;
  19. for(int i = 1; i <= N; i++)
  20. for(int j = 1; j <= N; j++)
  21. for(int k = 1; k <= N; k++)
  22. ret.x[i][j] = (ret.x[i][j] + x[i][k] * that.x[k][j]);
  23. return ret;
  24. }
  25. }I(1);
  26.  
  27. matrix power(matrix b, long long e)
  28. {
  29. matrix ret = I;
  30. while(e)
  31. {
  32. if(e&1) ret = ret * b;
  33. b = b * b;
  34. e /= 2;
  35. }
  36. return ret;
  37. }
  38.  
  39. double p;
  40.  
  41. double prob(int n, int k)
  42. {
  43. if(k > n) return 1;
  44. if(k < 1) return 0;
  45. matrix trans, init;
  46. trans.x[1][1] = 1/p; trans.x[1][2] = (p-1)/p; trans.x[2][1] = 1;
  47. init.x[1][1] = 1; init.x[2][1] = 0;
  48. init.x[1][1] = 1 / (power(trans, n) * init).x[1][1];
  49. return (power(trans, k-1) * init).x[1][1];
  50. }
  51.  
  52. class CatsOnTheCircle
  53. {
  54. public: double getProb(int N, int K, int _p)
  55. {
  56. p = _p / 1000000000.0;
  57. if(p < 0.5)
  58. {
  59. p = 1 - p;
  60. K = N - K;
  61. }
  62. double probR = prob(N-3, N-K-1);
  63. double probL = 1 - probR;
  64. if(probR < 0 || probR > 1) // INF
  65. return 0;
  66. return probR * (1 - prob(N-2, N-2)) + probL * prob(N-2, 1);
  67. }
  68. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty