[CSP-J 2021] 小熊的果篮

今年普及组复赛好水,模拟250轻轻松松
题目见小熊的果篮
这题不就是链表吗?水的要死

#include
#define N 200005
using namespace std;
struct Info {
	int x, pre, nxt;
};
Info a[N];
int h[N];
vector <int> v[2];
int main() {
	int n;
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
		a[i].pre = i - 1;
		a[i].nxt = i + 1;
	}
	a[0].x = 123;
	for (int i = 1; i <= n; i++)
		if (a[i].x != a[i - 1].x)
			v[0].push_back (i), h[i] = 1;
	int t = 0;
	while (v[t].size ()) {
		int s = t ^ 1;
		v[s].clear ();
		for (int i = 0, len = v[t].size (); i < len; i++) {
			int p = v[t][i];
			printf ("%d ", p);
			int le = a[p].pre, ri = a[p].nxt;
			a[le].nxt = ri, a[ri].pre = le;
			if (h[ri] == 0 && a[ri].x != a[le].x && ri <= n) {
				h[ri] = 1;
				v[s].push_back (ri), h[ri] = 1;
			}
		}
		cout << endl;
		t = s;
	}
	return 0;
}

你可能感兴趣的:(数据结构,c++,c语言,链表)