//
// main.cpp
// PATA1067
//
// Created by Phoenix on 2018/2/16.
// Copyright © 2018年 Phoenix. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100010;
int a[maxn];
int main(int argc, const char * argv[]) {
int n, num = 0, k = 1, t = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int b;
scanf("%d", &b);
a[b] = i;
if(b != i) num++;
}
if(a[0] == 0 && num > 0) num++;
while(num > 1) {
if(a[0] != 0) {
swap(a[0], a[a[0]]);
t++;
num--;
} else {
while(a[k] == k) k++;
swap(a[0], a[k]);
t++;
}
}
//if(num == 2) t++;
printf("%d", t);
return 0;
}
PATA1067题解
最新推荐文章于 2022-03-17 20:06:18 发布
337

被折叠的 条评论
为什么被折叠?



