B1042 Shuffling Machine (20分)
- A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j.
给定的顺序是[1,54]中不同整数的排列。如果第i个位置的数字是j,则意味着将卡从位置i移动到位置j。
其实就是类似于扑克牌的洗牌,把[1,54]对应的牌连按给的位置序列连续移K次,中间的两重循环脑子烧了写了毛半个小时🤦,边界处也不是处理得很好,又臭又长,打表两分钟就初始化好了。
晚安(  ̄ o  ̄ ) . z Z
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define lowbit(i)((i)&(-i))
using namespace std;
typedef long long ll;
const int MAX=1020;
const int INF=0x3f3f3f3f;
const int MOD=1000000007;
const int SQR=632;//633块,632个
int n;
int a[MAX],b[MAX],c[MAX];
map<int,string>mp;
void init()
{
string s;
for(int j=1;j<=4;j++)
{
for(int i=1;i<=13;i++)
{
if(j==1)
s='S';
else if(j==2)
s='H';
else if(j==3)
s='C';
else if(j==4)
s='D';
if(i>=10)
{
s+='1';
int t=i%10;
char temp=t+'0';
s+=temp;
}
else
{
char temp=i+'0';
s+=temp;
}
mp[13*(j-1)+i]=s;
}
}
mp[53]="J1";
mp[54]="J2";
for(int i=1;i<=54;i++)
c[i]=i;
}
int main()
{
init();
cin>>n;
for(int i=1;i<=54;i++)
scanf("%d",&a[i]);
for(int j=0;j<n;j++)
{
for(int i=1;i<=54;i++)
b[a[i]]=c[i];
for(int i=1;i<=54;i++)
c[i]=b[i];
}
for(int i=1;i<=54;i++)
{
if(i==1)
cout<<mp[c[i]];
else
cout<<" "<<mp[c[i]];
}
return 0;
}