I Hack Iself
查看原帖
I Hack Iself
155295
Peterwuwuwu楼主2020/8/4 16:43

I Hack IselfI\ Hack\ Iself

按照这个来写的点我点我点我

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
template<class T>
void read(T &x)
{
	T ans=0;short f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}while(ch>='0'&&ch<='9')
	{
		ans=(ans<<1)+(ans<<3)+(ch^48);
		ch=getchar();
	}x=ans*f;
}

#define maxn 2010
int n;
int x;
int s1[maxn],top1;
int s2[maxn],top2;
int base=1;
string ans;
void debug(){
	cout<<"sta1: ";
	for(int i=1;i<=top1;i++)cout<<s1[top1-i+1]<<' ';
	puts("");
	cout<<"sta2: ";
	for(int i=1;i<=top2;i++)cout<<s2[top2-i+1]<<' ';
	puts("\n");
}
signed main(){
#ifndef ONLINE_JUDGE
	freopen("testdata.in","r",stdin);
#endif
	read(n);
	for(int de=1;de<=n;de++){
	//	printf("op %d\n",de);
		read(x);
		if(x==base){
		//	printf("%d is pushed immediately and push a and b into ans\n",x);
			++base;
			ans+="a b ";
			continue;
		}
		while(s1[top1]==base||s2[top2]==base){
		//	printf("%d pushed\n",base);
			if(s1[top1]==base)ans+="b ",top1--;
			if(s2[top2]==base)ans+="d ",top2--;
			base++;
		}
		if(top1&&s1[top1]==x+1){
			s1[++top1]=x;
			ans+="a ";
		}
		else if(top2&&s2[top2]==x+1){
			s2[++top2]=x;
			ans+="c ";
		}
		else if(x<s1[top1]||top1==0){
		//	debug();
			s1[++top1]=x;
		//	cout<<"put a"<<endl;
			ans+="a ";
		}else if(x>s1[top1]){
		//	debug();
			if(x>s2[top2]&&!(s2[top2]==0)){
				puts("0");
				return 0;
			}
			s2[++top2]=x;
		//	cout<<"put c"<<endl;
			ans+="c ";
		}
	}
	while(s1[top1]==base||s2[top2]==base){
	//	printf("%d pushed\n",base);
		if(s1[top1]==base)ans+="b ",top1--;
		if(s2[top2]==base)ans+="d ",top2--;
		base++;
	}
	cout<<ans;
}
10
10 2 8 1 6 9 3 4 5 7

输出00,其实珂以的

2020/8/4 16:43
加载中...