RE求助
查看原帖
RE求助
298692
Rn_Lamsuly楼主2020/11/6 22:26

RT

#include<bits/stdc++.h>
using namespace std;
stack<int> z[5];
int main()
{
	int from[7];
	int to[7];
	int ans;
	int n;
	scanf("%d",&n);
	getchar();
	from[1]=getchar()-'A'+1;
	to[1]=getchar()-'A'+1;
	getchar();
	from[2]=getchar()-'A'+1;
	to[2]=getchar()-'A'+1;
	getchar();
	from[3]=getchar()-'A'+1;
	to[3]=getchar()-'A'+1;
	getchar();
	from[4]=getchar()-'A'+1;
	to[4]=getchar()-'A'+1;
	getchar();
	from[5]=getchar()-'A'+1;
	to[5]=getchar()-'A'+1;
	getchar();
	from[6]=getchar()-'A'+1;
	to[6]=getchar()-'A'+1;
	int sum1(0),sum2(0);
	int last=0;
	z[1].push(2);
	z[1].push(1);
	while(!(z[1].empty()&&(z[2].empty()||z[3].empty())))
	{
		for(register int i=1;i<=6;++i)
		{	
			if(z[from[i]].size())
			if(z[from[i]].top()!=last)
			{
				if(!z[to[i]].empty())
				{
					if(z[to[i]].top()>z[from[i]].top())
					{
					//	printf("move %d(%d) to %d(%d)\n",from[i],z[from[i]].top(),to[i],z[to[i]].top());
						last=z[from[i]].top();
						if(z[from[i]].top()==1)sum1++;
						else sum2++;
						z[to[i]].push(z[from[i]].top());
						z[from[i]].pop();
						break;
					}
					continue;
				}
				//printf("move %d(%d) to %d(none)\n",from[i],z[from[i]].top(),to[i]);
				last=z[from[i]].top();
				if(z[from[i]].top()==1)sum1++;
				else sum2++;
				z[to[i]].push(z[from[i]].top());
				//cout<<z[to[i]].top()<<' '<<z[to[i]].empty()<<endl;
				z[from[i]].pop();
				break;
			}
		}
	}
	//cout<<sum1<<' '<<sum2<<endl;
	long long f[35];
	f[1]=1;
	for(register int i=2;i<=n;++i)
	{
		f[i]=sum2+sum1*f[i-1];
	}
	cout<<f[n];
	return 0;
} 
2020/11/6 22:26
加载中...