软讯网络 > 编程语言 > C/C++ > My solution for SRM 306 DIV2 [250]
【标 题】:My solution for SRM 306 DIV2 [250]
【关键字】:
My,solution,for,SRM,306,DIV2,250
【来 源】:http://blog.csdn.net/Gooler/archive/2006/06/09/781944.aspx
My solution for SRM 306 DIV2 [250]
Problem Statement:
http://www.topcoder.com/stat?c=problem_statement&pm=6413&rd=9986My solution:
#include <iostream>
#include <vector>
using namespace std;
class SortMachine {
public:
SortMachine () {}
public:
int countMoves(vector <int> a) {
int countMove = 0;
while(1) {
int move = -1;
int minInversion = 1001;
for (unsigned int i = 0; i < a.size() - 1; ++i) {
for (unsigned int j = i + 1; j < a.size(); ++j) {
if (a[i] > a[j] && a[i] < minInversion) {
move = i;
minInversion = a[i];
break;
}
}
}
if (move == -1) {
break;
}
int temp = a[move];
for (unsigned int i = move; i < a.size() - 1; ++i) {
a[i] = a[i + 1];
}
a[a.size() - 1] = temp;
++countMove;
}
return countMove;
}
};