为什么会输出1 1 1 1 ……?
  • 板块学术版
  • 楼主whssy
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/10 23:28
  • 上次更新2023/11/3 04:35:23
查看原帖
为什么会输出1 1 1 1 ……?
809708
whssy楼主2023/8/10 23:28
#include<stdio.h>
#include<string.h>
#define N 200005
struct list{
	int flag,q[N],front,back;
	struct list *next;
	struct list *prev;
};
void clear(struct list *bt){
	memset(bt->q,0,sizeof bt->q);
	bt->front=1;
	bt->back=0;
	bt->flag=0;
	bt->next=NULL;
	bt->prev=NULL;
}
struct list *head=NULL;
struct list *tail=NULL;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int f;
		scanf("%d",&f);
		if(head==NULL){
			struct list dot;
			clear(&dot);
			dot.q[++dot.back]=i;
			dot.flag=f;
			head=&dot;
			tail=&dot;
		}else if(f!=tail->flag){
			struct list dot;
			printf("%d ",&dot==tail);
			clear(&dot);
			dot.q[++dot.back]=i;
			dot.flag=f;
			dot.prev=tail;
			tail->next=&dot;
			tail=&dot;
		}else tail->q[++tail->back]=i;
	}/*
	while(head->next!=NULL){
		for(struct list *p=head;p!=NULL;p=p->next)
			printf("%d ",p->q[p->front++]);
		putchar('\n');
		for(struct list *p=head;p!=NULL;p=p->next){
			if(p->front>p->back){
				if(p==head){
					head=head->next;
					head->next=NULL;
				}else if(p==tail){
					tail=tail->prev;
					tail->next=NULL;
				}else{
					p->prev->next=p->next;
					p->next->prev=p->prev;
				}
			}
		}
		for(struct list *p=head;p->next!=NULL;p=p->next){
			if(p->flag==p->next->flag){
				while(p->next->front<=p->next->back)
					p->q[++p->back]=p->next->q[p->next->front++];
				if(p==tail->prev){
					tail=p;
					tail->next=NULL;
				}else{
					p->next=p->next->next;
					p->next->prev=p;
				}
			}
		}
	}*/
	return 0;
}
2023/8/10 23:28
加载中...