Cod sursa(job #2575720)

Utilizator valentinchipuc123Valentin Chipuc valentinchipuc123 Data 6 martie 2020 15:09:22
Problema Tije Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.94 kb
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <stack>

#define INF 0x3f3f3f3f

using namespace std;

#ifdef DEBUG
string name = "data";
#else
string name = "tije";
#endif

ifstream fin(name + ".in");
ofstream fout(name + ".out");

#define MAXN 100

stack<int> t[MAXN + 2];
int n;

//vector<pair<int, int>> moves;

char buffer[7 * 2000000];
int ndx;

inline void writeNr(int x) {
    if (x <= 9) {
        buffer[ndx++] = x + '0';
        return;
    }
    if (x <= 99) {
        buffer[ndx++] = (x / 10) + '0';
        buffer[ndx++] = (x % 10) + '0';
        return;
    }
    buffer[ndx++] = '1';
    buffer[ndx++] = '0';

    buffer[ndx++] = x == 101 ? '1' : '0';
}

inline void exchange(int s, int d) {
    //    if (t[d].size() == n) {
    //        fout << "FATAL ERROR\n";
    //    }

    //    auto x = t[s].top();
    //    t[s].pop();
    //    t[d].push(x);
    //    moves.push_back({s, d});

    //    buffer += to_string(s) + " " + to_string(d) + "\n";

    writeNr(s);
    buffer[ndx++] = ' ';
    writeNr(d);
    buffer[ndx++] = '\n';

}

int main() {

    fin >> n;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            t[i].push(i);
        }
    }

    for (int i = 1; i < n ; ++i) {
        for (int j = i + 1; j <=n; ++j) {
            for (int k = i + 1; k <=n ; ++k) {
                exchange(j, n + 1);
            }
            for (int k = i + 1; k <=n ; ++k) {
                exchange(i, j);
            }
            exchange(n + 1, i);
            for (int k = i + 1; k <n ; ++k) {
                exchange(j, i);
            }
            for (int k = i + 1; k <n ; ++k) {
                exchange(n + 1, j);
            }
        }
    }

    fout << buffer;

    return 0;
}