WA 30pts求调
查看原帖
WA 30pts求调
905071
wbs123456楼主2024/10/19 13:55
#include<bits/stdc++.h>
using namespace std;
const int MAXN=5e2+5; 
int n,k,a[MAXN][MAXN],s[MAXN*MAXN+5],s2[MAXN*MAXN+5];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	if(k==1){
		cout<<1;
		return 0;
	}
	int tmp=n*n+1,pt=1,ch=1,to=2;
	while(tmp--){
		//cout<<ch<<" "<<to<<endl;
		s[pt]=ch;
		int temp=ch;
		ch=to;
		to=a[to][temp];
		pt++;
	}
	if(k<=n*n+1){
		cout<<s[k]<<endl;
		return 0;
	}
	int pt2=1,che=ch,ton=to;
	do
	{
// 		cout<<che<<" "<<ton<<endl;
		s2[pt2]=che;
		int temp=che;
		che=ton;
		ton=a[ton][temp];
		pt2++;
	}while(che!=ch||ton!=to);
	s2[pt2]=che;
	int temp=che;
	che=ton;
	ton=a[ton][temp];
// 	for(int i=1;i<=pt2;i++){
// 		cout<<s2[i]<<" ";
// 	}
	int tmp2=k-n*n-1;
	cout<<s2[tmp2%pt2];
	return 0;
}
2024/10/19 13:55
加载中...