P5550 Chino的数列

发布时间 2023-07-11 23:07:22作者: LsmQwQ

很想模拟,但是数据太大啦(悲。然后我想着用\(map\)映射来做,想着模拟几轮发现周期,然后映射求解。但是不知道为什么写崩了。勉强贴贴,反正不是正解(

#include <bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
const int N=80+10, INF=0x3f3f3f3f;
ll n,s,m,k;
ll a[N];
string S;
string To(ll x[N]){
	string y;
	for(re int i=1;i<=n;i++)y+=(x[i]+'0');
	return y;
}
map<string,bool> f;
map<int,string> f2;
int main(){
	int loop=0;
	cin>>n>>s>>m>>k;
	for(re int i=1;i<=n;i++)cin>>a[i];
	S=To(a);
	f[S]=0;
	f2[0]=S;
	while(f[S]){
		f[S]=1;
		loop++;
		swap(a[s],a[m]);
		int t=a[1];
		for(int i=1;i<n;i++)a[i]=a[i+1];
		a[n]=t;
		S=To(a);
		f2[loop]=S;
	}
	cout<<f2[k%loop]<<endl;
	return 0;
}