| ||||||||||
| 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 | |||||||||
cin的确比scanf慢,这不是OJ的问题,但是用cin也能过#include <iostream>
#include <memory.h>
using namespace std;
int id[100005], num[100005], hash[100005];
int main()
{
int t, n, i, r, next;
cin>>t;
while (t--)
{
cin>>n;
r = 0;
memset( hash, 0, sizeof(int)*100005 );
for ( i = 1; i <= n; i++ )
{
cin>>num[i];
id[num[i]] = i;
}
for ( i = 1; i <= n; i++ )
{
if ( hash[i] == 0 )
{
r++;
hash[i] = 1;
next = id[num[i]];
while ( hash[id[next]] == 0 )
{
hash[id[next]] = 1;
next = id[next];
}
}
}
cout<<n-r<<endl;
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator