题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<algorithm>
using namespace std;
int d[10005];
int n,ans;
int max1 = -1;
int max_i = -1;
int r_min(int x){
int ans = 9999;
int temp = -1;
for(int i = x;i<=n;i++){
if(d[i] < ans){
temp = i;
ans = d[i];
}
if(d[i] > max1){
max_i = i;
max1 = d[i];
}
}
return temp;
}
int main()
{
cin >> n;
for(int i = 1;i<=n;i++){
scanf("%d",&d[i]);
}
for(int i = 1;i<=n;i++){
int t_min = r_min(i);
if(t_min == i){
continue;
}else{
int temp = d[t_min];
d[t_min] = d[i];
d[i] = temp;
ans++;
}
}
cout << ans << endl;
return 0;
}