CF-1020B Badge

发布时间 2023-08-08 17:27:08作者: ~CHC~

Badge

【题意】:

从一个人徽章上打洞,他会说栽赃下一个人,然后下一个人的徽章被打洞,依次这样下去,直道某个人徽章有两个洞就结束。

【模拟】:

代表3个学生,第一名栽赃给第2个学生,第二名栽赃第3个,第三名栽赃给第2个

老师首先打洞1->2->3->2输出2;

再从第二 名学生2->3->2输出2;

再从第三名学生3->2->3输出3;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// #define ios ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const ll N = 1e4 + 10;
ll b[N],a[N];
void solve()
{
	ll n;
	cin >> n;
	for(ll i=1;i<=n;i++) cin>>a[i];

	for (ll i = 1; i <= n; i++)
	{
		ll tt = i;
		memset(b,0,sizeof b);
		while(1)
		{
			b[tt]++;
			tt=a[tt];
			if(b[tt]==2) break;
		}
		cout<<tt<<" \n"[i==n];
	}
}
int main()
{
	IOS
	// ll t;
	// cin >> t;
	// while (t--)
	solve();
	return 0;
}