fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double x[3][20] = {{0.0}};
  5.  
  6. int main() {
  7. x[0][0] = .4;
  8. x[1][0] = .4;
  9. x[2][0] = .2;
  10. double ans = 1.0;
  11. for(int i = 1; i < 10; i++) {
  12. x[0][i] = .5 * (x[0][i-1] + x[1][i-1]);
  13. x[1][i] = .25 * (x[0][i-1] + x[1][i-1]) + x[2][i-1];
  14. x[2][i] = .25 * (x[0][i-1] + x[1][i-1]);
  15.  
  16. ans += .5 * x[1][i-1];
  17. ans += .25 * x[0][i-1] + x[2][i-1];
  18. ans += .25 * (x[0][i-1] + x[1][i-1]);
  19. }
  20. cout << ans;
  21. return 0;
  22. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
7.3