使用C++14的程序
查看原帖
使用C++14的程序
86083
aceeca1楼主2021/11/7 17:38
#include <cstdio>
#include <list>
using namespace std;

struct Node {
    int Type, Id;
};

struct Solution {
    int N;
    list<list<Node>> L;

    void Solve() {
        scanf("%d", &N);
        int last = -1;
        for (int i = 0; i < N; ++i) {
            int x;
            scanf("%d", &x);
            if (x != last) L.emplace_back();
            L.back().emplace_back(Node{x, i});
            last = x;
        }
        while (!L.empty()) {
            list<list<Node>> newL;
            bool head = true;
            for (auto& i : L) {
                if (!head) printf(" ");
                head = false;
                printf("%d", 1 + i.front().Id);
                i.pop_front();
                if (!i.empty()) {
                    if (newL.empty() ||
                        newL.back().front().Type != i.front().Type) {
                        newL.emplace_back(move(i));
                    } else {
                        newL.back().splice(newL.back().end(), move(i));
                    }
                }
            }
            L = move(newL);
            printf("\n");
        }
    }
};

int main() {
    Solution().Solve();
    return 0;
}
2021/11/7 17:38
加载中...