Pagini recente » Cod sursa (job #349904) | Cod sursa (job #1509816) | Cod sursa (job #617041) | Cod sursa (job #720037) | Cod sursa (job #2541885)
#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;
string buffer;
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";
// fout << s << " " << d << "\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;
}