#include #include #include #include #include using namespace std; struct Card { int q, p; }; typedef vector VC; typedef vector VI; const int MAXT = 20; const int MAXN = 50000; int num_cases = MAXT; //assumes card pictures are from 0 to 2n-1 (n = v.size()) void dump(VC& v) { cout << v.size() << endl; for (auto c : v) cout << c.p+1 << ' ' << c.q+1 << endl; --num_cases; } void scramble(VC& v) { int n = v.size(); VI c(2*n); for (int i = 0; i < 2*n; ++i) c[i] = i; for (int i = 2*n-1; i > 0; --i) swap(c[i], c[rand()%(i+1)]); for (int i = 0; i < n; ++i) { if (rand()&1) swap(v[i].p, v[i].q); v[i].p = c[v[i].p]; v[i].q = c[v[i].q]; } } //random_yes, generated by assigning the first picture of card i to i //and the other to a random card, then scrambling void rand_yes(int n) { VC v(n); for (int i = 0; i < n; ++i) { v[i].p = i; v[i].q = rand()%n; } scramble(v); dump(v); } //first n-1 cards get random pictures from n-2 pictures, so there is not enough //last card has two new pictures, so the count is ok void rand_no(int n) { assert(n > 1); VC v(n); for (int i = 0; i < n-1; ++i) { v[i].p = i%(n-2); v[i].q = (i+1)%(n-2); } v[n-1].p = n-1; v[n-1].q = n; scramble(v); dump(v); } void full_rand(int n) { VC v(n); //Very interesting threshold. Using 2*n almost always produces //"yes" instances. This one seems close to 50/50. int mod = 39*n/20; for (int i = 0; i < n; ++i) { v[i].p = rand()%mod; v[i].q = rand()%mod; } dump(v); } int main() { cout << num_cases << endl; while (num_cases) if (num_cases&1) rand_yes(MAXN); else rand_no(MAXN); return 0; }