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

哪里错了呢??????!!!!!!!!!!!!!!!

Posted by huhuhuhh at 2010-03-13 18:25:13 on Problem 1674
#include<iostream>
using namespace std;
int a[10010];
int vis[10010];
int main()
{
	int t,n,i,k,temp;
	while(scanf("%d",&t)==1){
		for(i=0;i<t;i++){
			scanf("%d",&n);
			int count=0;
			for(k=0;k<n;k++){
				scanf("%d",&temp);
				a[temp]=k+1;
			}
			for(k=0;k<=n;k++) vis[k]=0;
			for(k=1;k<=n;k++){
				if(!vis[k]){
					temp=k;
					while(!vis[temp]){
						vis[temp]=1;
						temp=a[temp];						
					}
					count++;
				}
			}
			printf("%d\n",n-count);
		}	
	}	
	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