Bouncing Boomerangs

链接 : http://codeforces.com/problemset/problem/1428/D

参考于 : https://blog.csdn.net/qq_45928596/article/details/109140414

看了别人的思路写的, 狂wa, 惨!

代码
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define mod 1e9 + 7
const int N = 1e5 + 7;
int a[N], s1[N], s2[N];
int t1, t2;

int main() {
    IO;
    int n, last;
    cin >> n;
    int now = n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vector<PII> ans;
    for (int i = n; i; --i) {
        if (!a[i]) now--;
        if (a[i] == 1) {
            ans.pb({now, i});
            s1[++t1] = now--; 
        } else if (a[i] == 2) {
            if (!t1) {
                cout << "-1" << endl;
                return 0;
            }
            ans.pb({s1[t1--], i});
            s2[++t2] = i;                                                                                                                                 
        } else if (a[i] == 3) {
            //cout << t1 << " " << t2 << endl;
            if (!t1 && !t2) {
                cout << -1 << endl;
                return 0;
            }
            ans.pb({now, i});
            if (t2) last = s2[t2--];
            else last = s1[t1--];
            ans.pb({now, last});
            s2[++t2] = i;
            now--;
        }
    }
    cout << ans.size() << endl;
    for (auto t : ans) cout << t.fi << " " << t.se << endl;
    return 0;
}
posted @ 2020-11-17 19:44  phr2000  阅读(60)  评论(0编辑  收藏  举报