Arrival of the General
source link: http://codeforces.com/blog/entry/109051
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
using namespace std; int main(){ int n; cin>>n; int arr[n]; for(int m=0;m<n;m++){ cin>>arr[m]; }
int min_no=arr[0]; int indexmin = 0; for(int m=1;m<n;m++){
if (min_no >= arr[m]) { min_no = arr[m]; indexmin = m;
} } int min_moves = 0; for (int i = indexmin; i < n-1;i++){ swap(arr[i], arr[i + 1]); min_moves++; } int max_no = arr[n-1]; int indexmax = 0; for(int m=n-2;m>=0;m--){
if(max_no<=arr[m]){ max_no = arr[m]; indexmax = m; }} for (int i = indexmax; i >0;i--){ swap(arr[i], arr[i — 1]); min_moves++; } cout << min_moves << endl;
return 0;
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK