#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define sz(x) (int)x.size() #define cat(x) cerr << #x << " = " << x << endl #define IOS cin.tie(0); ios_base::sync_with_stdio(0) using ll = long long; using namespace std; int k, cnt[30], id = 1; vector<int> g[105]; int main() { scanf("%d", &k); for (int i = 0; i < 30; ++i) { int a = ++id, b = ++id; cnt[i] = a; if (i == 0) { g[a].pb(100); g[b].pb(100); } else { int c = a - 1, d = a - 2; g[a].pb(c); g[a].pb(d); g[b].pb(c); g[b].pb(d); } } int v = 1; for (int i = 29; 0 <= i; --i) { if (k >> i & 1) { g[v].pb(cnt[i]); int u = ++id; g[v].pb(u); v = u; } } printf("100\n"); for (int i = 1; i <= 100; ++i) { while (sz(g[i]) < 2) g[i].pb(-1); for (auto x : g[i]) printf("%d ", x); printf("\n"); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define sz(x) (int)x.size() #define cat(x) cerr << #x << " = " << x << endl #define IOS cin.tie(0); ios_base::sync_with_stdio(0) using ll = long long; using namespace std; int k, cnt[30], id = 1; vector<int> g[105]; int main() { scanf("%d", &k); for (int i = 0; i < 30; ++i) { int a = ++id, b = ++id; cnt[i] = a; if (i == 0) { g[a].pb(100); g[b].pb(100); } else { int c = a - 1, d = a - 2; g[a].pb(c); g[a].pb(d); g[b].pb(c); g[b].pb(d); } } int v = 1; for (int i = 29; 0 <= i; --i) { if (k >> i & 1) { g[v].pb(cnt[i]); int u = ++id; g[v].pb(u); v = u; } } printf("100\n"); for (int i = 1; i <= 100; ++i) { while (sz(g[i]) < 2) g[i].pb(-1); for (auto x : g[i]) printf("%d ", x); printf("\n"); } return 0; } |