Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <string.h>
- #include <queue>
- #include <math.h>
- #include <cmath>
- #include <map>
- #include <set>
- #include <vector>
- #include <algorithm>
- #include <bitset>
- #include <list>
- #include <ctype.h>
- #include <cassert>
- #include <stack>
- #include <fstream>
- #include <unordered_map>
- #include <unordered_set>
- #include <ctime>
- #include <functional>
- #include <ctime>
- #include <limits>
- using namespace std;
- #define snd second
- #define fst first
- #define mp make_pair
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define pb push_back
- #define left _left
- #define right _right
- const ld pi = 3.14159265359;
- template<typename T>
- T abs(T x) {
- return x > 0 ? x : -x;
- }
- template<typename T>
- T sqr(T x) {
- return x * x;
- }
- template<typename T>
- void chmin(T &x, T y) {
- x = min(x, y);
- }
- template<typename T>
- void chmax(T &x, T y) {
- x = max(x, y);
- }
- template<typename U, typename V>
- ostream &operator<<(ostream &s, const pair<U, V> &x) {
- s << "(" << x.fst << ", " << x.snd << ")";
- return s;
- }
- template<typename U>
- ostream &operator<<(ostream &s, const vector<U> &x) {
- s << "[";
- bool was = false;
- for (auto it : x) {
- if (was) {
- s << ", ";
- }
- was = true;
- s << it;
- }
- s << "]";
- return s;
- }
- template<typename U>
- ostream &operator<<(ostream &s, const set<U> &x) {
- s << "{";
- bool was = false;
- for (auto it : x) {
- if (was) {
- s << ", ";
- }
- was = true;
- s << it;
- }
- s << "}";
- return s;
- }
- template<int sz>
- ostream operator << (ostream &s, const bitset<sz> &x) {
- for (int i = 0; i < sz; i++) {
- s << x[i];
- }
- return s;
- }
- //-----------------------------------------------------------------------------
- struct M {
- ll a[3][3];
- M() {
- for (int i = 0; i < 3; i++) {
- fill(a[i], a[i] + 3, 0);
- }
- }
- M operator * (const M &o) const {
- M res;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- for (int k = 0; k < 3; k++) {
- res.a[i][j] += a[i][k] * o.a[k][j];
- }
- }
- }
- return res;
- }
- };
- map<pair<int,int>, ll> was;
- ll f(ll a, ll b, int n) {
- if (!n) {
- return b;
- }
- if (was.count(mp(a, b))) {
- return was[mp(a, b)];
- }
- return was[mp(a, b)] = f(b, a + b, n - 1) + f(b, abs(a - b), n - 1);
- }
- int main() {
- srand(time(NULL));
- retry:
- #ifdef LOCAL
- //gen();
- //cerr << 1 << endl;
- freopen("a.in", "r", stdin);
- #else
- //freopen("fract.in", "r", stdin);
- //freopen("fract.out", "w", stdout);
- #endif
- map<pair<ll, ll>, ll> a;
- a[mp(0, 1)] = 1;
- int n = 0;
- while (true) {
- map<pair<ll, ll>, ll> b;
- for (auto kv : a) {
- b[mp(kv.fst.snd, kv.fst.fst + kv.fst.snd)] += kv.snd;
- b[mp(kv.fst.snd, abs(kv.fst.fst - kv.fst.snd))] += kv.snd;
- }
- ld sum = 0.0, prvSum = 0.0;
- for (auto kv : a) {
- prvSum += (ld)kv.fst.snd * kv.snd;
- }
- ll m = 0;
- for (auto kv : b) {
- sum += (ld)kv.fst.snd * kv.snd;
- m = max(m, kv.fst.snd);
- }
- cout.precision(10);
- cout << ++n << " - " << fixed << 0.5 * sum / prvSum << endl;
- a = b;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement