Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:暴swap闪过!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator