#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#include<cstring>
using namespace std;
int c;
int p[100010];
int main()
{
int n;
scanf("%d",&n);
int left=n-1;
for(int i=0;i<n;i++)
{
scanf("%d",&c);
p[c]=i;
if(c==i&&c!=0)
left--;
}
int time=0;
int k=1;
while(left>0)
{
if(p[0]==0)
{
while(k<n)
{
if(p[k]!=k)
{
swap(p[0],p[k]);
time++;
break;
}
k++;
}
}
while(p[0]!=0)
{
swap(p[0],p[p[0]]);
time++;
left--;
}
}
printf("%d",time);
system("pause");
return 0;
}
PAT 1067
最新推荐文章于 2021-02-20 21:48:13 发布