fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define lb lower_bound
  6. #define ub upper_bound
  7. #define pb push_back
  8. #define pf push_front
  9. #define mp make_pair
  10. #define gcd __gcd
  11. #define all(x) x.begin(), x.end()
  12. #define S(x) scanf("%d", &x)
  13. #define Sl(x) scanf("%lld", &x)
  14. #define P(x) printf("%d", x)
  15. #define Pl(x) printf("%lld", x)
  16. #define PS(x) printf("%s", x)
  17. #define MOD 1000000007LL
  18.  
  19. typedef long long ll;
  20. typedef vector<int> vi;
  21. typedef vector<vi> vvi;
  22. typedef pair<int, int> ii;
  23. typedef vector<ii> vii;
  24.  
  25. double as[100005];
  26. int main()
  27. {
  28. int t,n;
  29. S(t);
  30. double p;
  31. while(t--) {
  32. scanf("%d",&n);
  33. scanf("%lf",&p);
  34. as[0] = 0;
  35. as[1] = 2;
  36. as[2] = 2;
  37. for(int i = 3; i <= n; i++) {
  38. as[i] = (as[i-2]+2)*p + ((as[i-3]+2)*(1-p));
  39. }
  40. printf("%0.2lf\n", as[n]);
  41. }
  42. return 0;
  43. }
  44.  
Runtime error #stdin #stdout 0s 4192KB
stdin
Standard input is empty
stdout
Standard output is empty