社区讨论

50分求助

P7912[CSP-J 2021] 小熊的果篮参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lobab1ef
此快照首次捕获于
2023/10/29 17:44
2 年前
此快照最后确认于
2023/11/03 23:41
2 年前
查看原帖

有隐蔽错误

CPP
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n;
struct tNode {
	int prv,nxt;
	int left, right;
	int d;
} nodes[200005];
bool vis[200005];
int lstnode,head,tail;
int main() {
//	freopen("fruit.in","r",stdin);
//	freopen("fruit.out","w",stdout);
	head = 1;
	tail = 2;
	lstnode = 3;
	nodes[head].left = nodes[head].right = 0;
	nodes[tail].left = nodes[tail].right = 0;
	nodes[head].nxt = tail;
	nodes[head].prv = -1;
	nodes[tail].prv = head;
	nodes[tail].nxt = -1;
	nodes[head].d = 7;
	nodes[tail].d = 8;
	int last=7;
	scanf("%d",&n);
	int p=0;	// 当前节点
	for(int i=1; i<=n; i++) {
		int data;
		scanf("%d",&data);
		if(last != data) {
			p = lstnode++;
			nodes[p].d = data;
			nodes[p].left = i;
			nodes[p].right = i;
			nodes[p].nxt = tail;
			nodes[p].prv = nodes[tail].prv;
			nodes[tail].prv = p;
			nodes[nodes[p].prv].nxt = p;
			last = data;
		} else {
			nodes[p].right = i;
//			printf("p=%d,left=%d, right=%d\n",p,nodes[p].left, nodes[p].right);
		}
	}
//	nodes[p].right = n;
	for(; nodes[head].nxt != tail; ) {
		last = 7;
		for( p=nodes[head].nxt; p!=tail; p=nodes[p].nxt) {
			if(last != nodes[p].d) {
				for(; vis[nodes[p].left] == true; ) nodes[p].left++;
				printf("%d ",nodes[p].left);
				vis[nodes[p].left] = true;
				if(nodes[p].left == nodes[p].right) {
					nodes[nodes[p].prv].nxt = nodes[p].nxt;
					nodes[nodes[p].nxt].prv = nodes[p].prv;
				} else {
					nodes[p].left++;
				}
				last = nodes[p].d;
			} else {	// last == nodes[p].d  和上一段一样
				int pp = nodes[p].prv;
				nodes[pp].right = nodes[p].right;
				nodes[pp].nxt = nodes[p].nxt;
				nodes[nodes[p].nxt].prv = pp;
			}
		}
		printf("\n");
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...