Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)E. Petya and Construction ...

https://codeforc.es/contest/1214/problem/E

借鉴自dls的做法:先把奇数号从长到短连接起来然后连剩下的偶数号。

 1 #define bug(x) cout<<#x<<" is "<<x<<endl
 2 #define IO std::ios::sync_with_stdio(0)
 3 #include <bits/stdc++.h>
 4 #define iter ::iterator
 5 #define pa pair<int,int>
 6 using namespace  std;
 7 #define ll long long
 8 #define mk make_pair
 9 #define pb push_back
10 #define se second
11 #define fi first
12 #define ls o<<1
13 #define rs o<<1|1
14 ll mod=998244353;
15 const int N=2e5+5;
16 int n;
17 pa p[N];
18 vector<pa>ans;
19 int pos[N];
20 int main(){
21     IO;
22     cin>>n;
23     for(int i=1;i<=n;i++){
24         cin>>p[i].fi;
25         p[i].se=i;
26     }
27     sort(p+1,p+1+n);
28     reverse(p+1,p+1+n);
29     for(int i=1;i<=n;i++){
30         pos[i]=p[i].se*2-1;
31         if(i>1){
32             ans.pb(mk(pos[i-1],pos[i]));
33         } 
34     }
35     int len=n;
36     for(int i=1;i<=n;i++){
37         int c=i+p[i].fi;
38         if(c==len+1){
39             pos[c]=p[i].se*2;
40             ans.pb(mk(pos[c-1],pos[c]));
41             len++;
42         }
43         else{
44             ans.pb(mk(pos[c-1],2*p[i].se));
45         }
46     }
47     for(auto p: ans){
48         cout<<p.fi<<" "<<p.se<<endl;
49     }
50 }

 

转载于:https://www.cnblogs.com/ccsu-kid/p/11469061.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值