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 |
一次AC 贴一下代码#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> using namespace std; int main() { int n,a[10002]; int t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",a+i); int sum=0; for(int i=1;i<=n;++i) while(a[i]!=i) swap(a[i],a[a[i]]),++sum; printf("%d\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator