题目https://codeforces.com/problemset/problem/1214/E
就是得知奇数之间不产生影响,先造出一条链,再用偶数往里插就行。链要di从大到小排个序呀!!
#include<cstdio> #include<iostream> #include<algorithm> #include<vector> #define maxn 202000 using namespace std; struct Node { int ans; int pos; }list[maxn]; bool bml(Node a, Node b) { return a.ans > b.ans; } vector<int>ans; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &list[i].ans); list[i].pos = i * 2 - 1;//奇数 } sort(list + 1, list + 1 + n, bml); for (int i = 1; i < n; i++) { printf("%d %d\n", list[i].pos, list[i + 1].pos); ans.push_back(list[i].pos); } ans.push_back(list[n].pos); for (int i = 1; i <= n; i++) { int t = list[i].ans + i - 2; printf("%d %d\n", ans[t], list[i].pos + 1); if (ans.size()-1 == t) ans.push_back(list[i].pos + 1); } return 0; }