fork download
  1. #include <bits/stdc++.h>
  2. #define MP make_pair
  3. #define PB push_back
  4. #define int long long
  5. #define st first
  6. #define nd second
  7. #define rd third
  8. #define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
  9. #define RE(i, n) FOR(i, 1, n)
  10. #define FORD(i, a, b) for(int i = (a); i >= (b); --i)
  11. #define REP(i, n) for(int i = 0;i <(n); ++i)
  12. #define VAR(v, i) __typeof(i) v=(i)
  13. #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
  14. #define ALL(x) (x).begin(), (x).end()
  15. #define SZ(x) ((int)(x).size())
  16. using namespace std;
  17. template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
  18. template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  19. while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
  20. }
  21. #ifdef LOCAL
  22. #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
  23. #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
  24. #else
  25. #define debug(...) (__VA_ARGS__)
  26. #define debugv(x)
  27. #define cerr if(0)cout
  28. #endif
  29. #define make(type, x) type x; cin>>x;
  30. #define make2(type, x, y) type x, y; cin>>x>>y;
  31. #define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
  32. #define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
  33. #define next ____next
  34. #define prev ____prev
  35. #define left ____left
  36. #define hash ____hash
  37. typedef long long ll;
  38. typedef long double LD;
  39. typedef pair<int, int> PII;
  40. typedef pair<ll, ll> PLL;
  41. typedef vector<int> VI;
  42. typedef vector<VI> VVI;
  43. typedef vector<ll> VLL;
  44. typedef vector<pair<int, int> > VPII;
  45. typedef vector<pair<ll, ll> > VPLL;
  46.  
  47. template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
  48. template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
  49. template<class T1, class T2>
  50. ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
  51. template<class A, class B, class C> struct Triple { A first; B second; C third;
  52. bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
  53. template<class T> void ResizeVec(T&, vector<int>) {}
  54. template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  55. vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  56. for (T& v : vec) { ResizeVec(v, sz); }
  57. }
  58. typedef Triple<int, int, int> TIII;
  59. template<class A, class B, class C>
  60. ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
  61. template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  62.  
  63. const int N = 1e4 + 5;
  64. LD p[N];
  65. LD dp[2][N][7];
  66.  
  67. #undef int
  68. int main() {
  69. #define int long long
  70.  
  71. ios_base::sync_with_stdio(0);
  72. cout << fixed << setprecision(10);
  73. cerr << fixed << setprecision(10);
  74. cin.tie(0);
  75. //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  76.  
  77. LD E1 = 0;
  78. RE (i, 6) {
  79. cin>>p[i];
  80. E1 += i * p[i];
  81. dp[0][i][i] = p[i];
  82. }
  83. int n;
  84. cin>>n;
  85. LD V1 = 0;
  86. RE (i, 6) {
  87. LD diff = i - E1;
  88. V1 += diff * diff * p[i];
  89. }
  90. debug(E1, V1);
  91.  
  92. int cap = min(n, (int)1500);
  93. int cur = 1;
  94. RE (i, cap - 1) {
  95. debug(i);
  96. RE (sum, 6 * i) {
  97. RE (last, 6) {
  98. dp[cur][sum][last] = 0;
  99. }
  100. }
  101. RE (sum, 6 * i) {
  102. RE (last, 6) {
  103. RE (now, 6) {
  104. if (now != last) {
  105. dp[cur][sum + now][now] += dp[cur ^ 1][sum][last] * p[now] / (1 - p[last]);
  106. }
  107. }
  108. }
  109. }
  110. cur ^= 1;
  111. }
  112. LD E[2], V[2];
  113. REP (tr, 2) {
  114. E[tr] = V[tr] = 0;
  115. RE (sum, 6 * cap) {
  116. RE (last, 6) {
  117. E[tr] += dp[tr][sum][last] * sum;
  118. }
  119. }
  120. RE (sum, 6 * cap) {
  121. RE (last, 6) {
  122. LD diff = sum - E[tr];
  123. V[tr] += diff * diff * dp[tr][sum][last];
  124. }
  125. }
  126. }
  127. if (E[0] > E[1]) {
  128. swap(E[0], E[1]);
  129. swap(V[0], V[1]);
  130. }
  131. LD resE = (n - cap) * (E[1] - E[0]) + E[1];
  132. LD resV = (n - cap) * (V[1] - V[0]) + V[1];
  133. cout<<resE<<"\n"<<resV<<"\n";
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. return 0;
  158. }
  159.  
Success #stdin #stdout 0s 5208KB
stdin
Standard input is empty
stdout
0.0000000000
0.0000000000