AcWing 1762. 牛的洗牌
作者:互联网
思路:暴力逆推3次,我们发现上一轮和本轮的关系是preid[i]=id[a[i]]
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int a[N],id[N];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin >> id[i];
for(int k=0;k<3;k++){
int p[N];
for(int i=1;i<=n;i++) p[i]=id[a[i]];
memcpy(id,p,sizeof p);
}
for(int i=1;i<=n;i++)
cout<< id[i] << endl;
return 0;
}
标签:preid,const,int,洗牌,110,1762,include,id,AcWing 来源: https://blog.csdn.net/qq_43619680/article/details/122788220