Gravatar
梵高
积分:18
提交:14 / 19
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int Hen_hen_eaaaaa(233333);struct Eat{ int Now,Nxt,Bef,Col;}eat[Hen_hen_eaaaaa],frt[Hen_hen_eaaaaa];int n,cnt,STT;bool NOW;inline int R(){ int x=0,f=1;char c='c'; while(c>'9'||c<'0'){f=f*(c=='-'?-1:1);c=getchar();} while(c<='9'&&c>='0'){x=x*10+c-'0';c=getchar();} return x*f;}int main(){ freopen("csp2021pj_fruit.in","r",stdin); freopen("csp2021pj_fruit.out","w",stdout); n=R(); if(!n) return 0; for(int i=1;i<=n;++i){frt[i].Col=R();frt[i].Bef=i-1;frt[i-1].Nxt=i;} NOW=!frt[1].Col;frt[0].Nxt=1; for(int i=1;i<=n;++i){ if(frt[i].Col!=NOW){ NOW=frt[i].Col; eat[++cnt].Now=i; eat[cnt].Bef=cnt-1; eat[cnt-1].Nxt=cnt; } } int N,NN,NNN; while(frt[0].Nxt&&eat[0].Nxt){ N=eat[0].Nxt; while(N){ printf("%d ",eat[N].Now); NN=eat[N].Now; frt[frt[NN].Bef].Nxt=frt[NN].Nxt; frt[frt[NN].Nxt].Bef=frt[NN].Bef; eat[N].Now=frt[NN].Nxt; NNN=eat[N].Now; if(((frt[NNN].Col!=frt[NN].Col)||(!NNN))&&((frt[eat[eat[N].Bef].Now].Col!=frt[NN].Col)||(!eat[N].Bef))){ eat[eat[N].Bef].Nxt=(eat[N].Bef?((eat[eat[N].Nxt].Nxt&&eat[N].Nxt)?eat[eat[N].Nxt].Nxt:0):eat[N].Nxt); eat[eat[eat[N].Nxt].Nxt].Bef=((eat[N].Bef&&eat[eat[N].Nxt].Nxt&&eat[N].Nxt)?eat[N].Bef:eat[eat[eat[N].Nxt].Nxt].Bef); eat[eat[N].Nxt].Bef=((eat[N].Bef||!eat[N].Nxt)?eat[eat[N].Nxt].Bef:0); } N=eat[N].Nxt; } printf("\n"); } return 0;}

题目3618  [CSP 2021J]小熊的果篮      1      评论
2023-07-12 17:43:24