#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#define N 100005
#define ll long long
using namespace std;
vector<pair<int,int> >v;
int a[N],pos[N],vis[N];
int main()
{
int n,i,j,ans;
while(scanf("%d",&n)!=EOF)
{
ans = 0;
for(i = 0;i<n;i++)
{
scanf("%d",&a[i]);
pos[a[i]] = i;
}
for(i = 0;i<n;i++)
{
if(!vis[i]&&a[i]!=i)
{
vis[i] = 1;
j = pos[i];
while(j!=i)
{
vis[j] = 1;
j = pos[j];
ans++;
}
ans+=2;
}
}
if(a[0]!=0)ans-=2;
printf("%d\n",ans);
}
return 0;
}
pat1067 Sort with Swap(0,*)
最新推荐文章于 2019-11-21 00:37:00 发布