跳到正文

题解

题解:P2923 [USACO08DEC] Winning Checkers G

TangLingxin约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P2923

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
struct kuai
{
	int st, ed, th;
}f, x, ad;
int n, cnt, t[200002];
queue<kuai> q, q2;
bool used[200001];
int main(){
	scanf("%d", &n);
	for (int i = 1;i <= n;i ++) scanf("%d", &t[i]);
	t[n + 1] = !t[n];
	for (int i = 2, si = 1;i <= n + 1;i ++){
		if (t[i] != t[i - 1]) q.push((kuai){si, i - 1, t[i - 1]}), si = i;
	}
	cnt = n;
	while (cnt){
		while (q.size()){
			f = q.front();
			q.pop();
			while (used[f.st] && f.st <= f.ed) f.st ++;
			if (f.st > f.ed) continue;
			printf("%d ", f.st), cnt --;
			used[f.st] = 1;
			if (f.ed == f.st) continue;
			f.st ++;
			q2.push(f);
		}
		putchar('\n');
		while (q2.size()){
			ad = q2.front();
			q2.pop();
			while (q2.size()){
				x = q2.front();
				if (x.th == ad.th)
				{
					ad.ed = x.ed;
					q2.pop();
				}
				else break;
			}
			q.push(ad);
		}
	}
    bool *p;
    for(int i=1;i<=10000000;i++)
    {
    	p=new bool;
	}
}
原文