Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:暴swap闪过!

Posted by qylsw at 2010-07-20 10:08:50 on Problem 1674
In Reply To:暴swap闪过! Posted by:19910517 at 2010-02-04 10:59:46
#include<iostream>
using namespace std;
int main()
{
	int x;
	cin>>x;
	while(x--){
		int c=0,n,a[20000],i,visit[20000]={0},tmp;
		cin>>n;
		for(i=1;i<=n;i++) cin>>a[i];
		for(i=1;i<=n;i++){
			if(visit[i]==1) continue;
			tmp=i;
			do{
				visit[tmp]=1;
				tmp=a[tmp];
			}while(visit[tmp]==0);
			c++;
		}
		cout<<n-c<<endl;
	}
	return 0;
}
				
		
		

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator