#include<iostream> #include<algorithm> #include<unordered_map> usingnamespace std; constint N = 1e5 + 10; int a[N * 2]; unordered_map<int, int> b; int n, res, k;
intmain() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n; int m = n * 2; for (int i = 1; i <= m; i++) { int x; cin >> x; b[x]++; } for (auto k:b) { if (k.second % 2) { cout << -1; return0; } }
for (auto k:b) { for (int i = 0; i < k.second / 2; i++) cout << k.first << " "; } cout << '\n'; for (auto k:b) { for (int i = 0; i < k.second / 2; i++) cout << k.first << " "; }
#include<iostream> #include<algorithm> usingnamespace std; constint N = 1e5 + 10; int a[N * 2]; int n;
intmain() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n; int m = n * 2; for (int i = 1; i <= m; i++) cin >> a[i]; sort(a + 1, a + m + 1); for (int i = 2; i <= m; i += 2) { if (a[i] != a[i - 1]) { cout << -1; return0; } } for (int i = 2; i <= m; i += 2) cout << a[i] << " "; cout << '\n'; for (int i = 2; i <= m; i += 2) cout << a[i] << " ";
usingnamespace std; typedeflonglong LL; constint N = 1e5 + 10; LL a[N]; LL n, k,res;
intmain() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { LL kk = a[i]; LL l = 1, r = n; while (l < r) { LL mid = l + r + 1 >> 1; if (a[mid] <= kk + k) l = mid; else r = mid - 1; } res = max(res, r - i + 1); }
#define x first #define y second usingnamespace std; typedef pair<int, int> PII; constint N = 1e5 + 10; PII a[N], p[N]; int st[N]; int b[N]; int n, k, kk;
intmain() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x <= n) st[x] ++; a[i] = {x, i}; } sort(a, a + n); for (int i = 1; i <= n; i++) { if (!st[i]) b[k++] = i; }
for (int i = 1; i <= n; i++) { if (a[i].x <= n && st[a[i].x] > 1) { p[kk++] = {a[i].y, b[--k]}; st[a[i].x]--; } elseif (a[i].x <= n && st[a[i].x] == 0) p[kk++] = {a[i].y, b[--k]}; elseif (a[i].x > n) p[kk++] = {a[i].y, b[--k]}; }
cout << kk << '\n'; for (int i = 0; i < kk; i++) cout << p[i].x << " " << p[i].y << '\n'; return0; }
#define x first #define y second usingnamespace std; constint N = 2e5 + 10; int dist[N]; vector<int> g[N]; int n, m, ma;
intmain() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> dist[i]; ma = max(ma, dist[i]); // 获得所有点的最大值 // g[dist[i]].push_back(i); }
for (int i = 1; i <= ma; i++){ // 将所有结点和它比它距离小1的结点相连 // if(g[i].empty()) { // 如果出现空的情况,就意味着对于1~ma有断点的存在,那么这种情况我们就肯定无法生成一个图// cout << -1; return0; } for (auto j : g[i]) { // 如果不是空,就将结点和最短距离小于1的结点进行连接 vis.push_back({g[i - 1][0], j}); } }
// 如果现在还有边需要相连接,那么就将同一层之间所有结点之间进行相连,因为这种连线是不存在意义的,不会影响路径大小// for (int i = 1; i <= ma && vis.size() < m; i++){ for (int j = 0; j < g[i].size() && vis.size() < m; j++){ for (int k = j + 1; k < g[i].size() && vis.size() < m; k++) { vis.push_back({g[i][j], g[i][k]}); } } for (int j = 1; j < g[i].size() && vis.size() < m; j++) { for (int k = 0; k < g[i + 1].size(); k++) { vis.push_back({g[i][j],g[i + 1][k]}); } } }