Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <string.h>
  5. #include <queue>
  6. #include <math.h>
  7. #include <cmath>
  8. #include <map>
  9. #include <set>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <bitset>
  13. #include <list>
  14. #include <ctype.h>
  15. #include <cassert>
  16. #include <stack>
  17. #include <fstream>
  18. #include <unordered_map>
  19. #include <unordered_set>
  20. #include <ctime>
  21. #include <functional>
  22. #include <ctime>
  23. #include <limits>
  24.  
  25. using namespace std;
  26.  
  27. #define snd second
  28. #define fst first
  29. #define mp make_pair
  30. #define ll long long
  31. #define ull unsigned long long
  32. #define ld long double
  33. #define pb push_back
  34. #define left _left
  35. #define right _right
  36.  
  37. const ld pi = 3.14159265359;
  38.  
  39. template<typename T>
  40. T abs(T x) {
  41. return x > 0 ? x : -x;
  42. }
  43.  
  44. template<typename T>
  45. T sqr(T x) {
  46. return x * x;
  47. }
  48.  
  49. template<typename T>
  50. void chmin(T &x, T y) {
  51. x = min(x, y);
  52. }
  53.  
  54. template<typename T>
  55. void chmax(T &x, T y) {
  56. x = max(x, y);
  57. }
  58.  
  59. template<typename U, typename V>
  60. ostream &operator<<(ostream &s, const pair<U, V> &x) {
  61. s << "(" << x.fst << ", " << x.snd << ")";
  62. return s;
  63. }
  64.  
  65. template<typename U>
  66. ostream &operator<<(ostream &s, const vector<U> &x) {
  67. s << "[";
  68. bool was = false;
  69. for (auto it : x) {
  70. if (was) {
  71. s << ", ";
  72. }
  73. was = true;
  74. s << it;
  75. }
  76. s << "]";
  77. return s;
  78. }
  79.  
  80. template<typename U>
  81. ostream &operator<<(ostream &s, const set<U> &x) {
  82. s << "{";
  83. bool was = false;
  84. for (auto it : x) {
  85. if (was) {
  86. s << ", ";
  87. }
  88. was = true;
  89. s << it;
  90. }
  91. s << "}";
  92. return s;
  93. }
  94.  
  95. template<int sz>
  96. ostream operator << (ostream &s, const bitset<sz> &x) {
  97. for (int i = 0; i < sz; i++) {
  98. s << x[i];
  99. }
  100. return s;
  101. }
  102.  
  103.  
  104. //-----------------------------------------------------------------------------
  105.  
  106.  
  107. struct M {
  108. ll a[3][3];
  109. M() {
  110. for (int i = 0; i < 3; i++) {
  111. fill(a[i], a[i] + 3, 0);
  112. }
  113. }
  114. M operator * (const M &o) const {
  115. M res;
  116. for (int i = 0; i < 3; i++) {
  117. for (int j = 0; j < 3; j++) {
  118. for (int k = 0; k < 3; k++) {
  119. res.a[i][j] += a[i][k] * o.a[k][j];
  120. }
  121. }
  122. }
  123. return res;
  124. }
  125. };
  126.  
  127. map<pair<int,int>, ll> was;
  128.  
  129. ll f(ll a, ll b, int n) {
  130. if (!n) {
  131. return b;
  132. }
  133.  
  134. if (was.count(mp(a, b))) {
  135. return was[mp(a, b)];
  136. }
  137.  
  138. return was[mp(a, b)] = f(b, a + b, n - 1) + f(b, abs(a - b), n - 1);
  139. }
  140.  
  141. int main() {
  142. srand(time(NULL));
  143.  
  144. retry:
  145.  
  146. #ifdef LOCAL
  147. //gen();
  148. //cerr << 1 << endl;
  149. freopen("a.in", "r", stdin);
  150. #else
  151. //freopen("fract.in", "r", stdin);
  152. //freopen("fract.out", "w", stdout);
  153. #endif
  154.  
  155. map<pair<ll, ll>, ll> a;
  156. a[mp(0, 1)] = 1;
  157.  
  158. int n = 0;
  159. while (true) {
  160. map<pair<ll, ll>, ll> b;
  161. for (auto kv : a) {
  162. b[mp(kv.fst.snd, kv.fst.fst + kv.fst.snd)] += kv.snd;
  163. b[mp(kv.fst.snd, abs(kv.fst.fst - kv.fst.snd))] += kv.snd;
  164. }
  165.  
  166. ld sum = 0.0, prvSum = 0.0;
  167. for (auto kv : a) {
  168. prvSum += (ld)kv.fst.snd * kv.snd;
  169. }
  170. ll m = 0;
  171. for (auto kv : b) {
  172. sum += (ld)kv.fst.snd * kv.snd;
  173. m = max(m, kv.fst.snd);
  174. }
  175. cout.precision(10);
  176. cout << ++n << " - " << fixed << 0.5 * sum / prvSum << endl;
  177. a = b;
  178. }
  179.  
  180.  
  181. return 0;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement