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 |
why wa?#include<iostream.h> int a[10001],b[10001]; int main() { int t,ca,n,i,j,k,s; cin>>t; for(ca=0;ca<t;ca++) { cin>>n; for(i=0;i<=n;i++)a[i]=i; for(i=0;i<=n;i++)b[i]=0; for(i=1;i<=n;i++) { cin>>s; j=i;k=a[i]; while(j!=k){j=k;k=a[k];}a[s]=k; j=i;k=a[i];while(j!=k){a[j]=a[s];j=k;k=a[k];} } for(i=1;i<=n;i++) { b[a[i]]++; } j=0; for(i=1;i<=n;i++)if(a[i]==i) j+=b[i]-1; cout<<j<<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