题解:P1698 [USACO18JAN] Out of Place B

· · 题解

AC代码:

include<bits/stdc++.h>

using namespace std;

int w[100001],re[100001];

int main(){

int h;

cin>>h;

for(int j=1;j<=h;j++){

cin>>w[j];

re[j]=w[j];

}

sort(re+1,re+h+1);

int sum=-1;

for (int j=1;j<=h;j++){

if (w[j]!=re[j]){

sum++;

}

}

cout<<sum;

return 0;

}