My solution for SRM 306 DIV2 [250]
2006-06-09 09:05
531 查看
Problem Statement: http://www.topcoder.com/stat?c=problem_statement&pm=6413&rd=9986
My 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;
}
};
My 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;
}
};
相关文章推荐
- TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%
- 记第一次TopCoder, 练习SRM 583 div2 250
- 最小公倍数 SRM 661 Div1 250: MissingLCM
- [TopCoder] SRM 587 DIV 2, 250p, 500p, 1000p, Solution
- SRM 576 250 DIV2
- Codeforces Round #444 (Div. 2) C. Solution for Cube
- Codeforces Round #444 (Div. 2) C. Solution for Cube【模拟】
- Codeforces Round #444 (Div. 2)-C-Solution for Cube(魔方一步还原)
- TopCoder 250 points 4-SRM 145 DIV 2 128.72/250 51.49%
- TopCoder 250 points 8-SRM 147 DIV 2 176.36/250 70.54%
- TopCoder 250 points 9-SRM 148 DIV 1 75/250 30%
- TopCoder 250 points 11-SRM 149 DIV 1 86.62/250 34.65%
- TopCoder 250 points 14-SRM 150 DIV 2 86.25/250 34.50%
- TopCoder 250 points 16-SRM 151 DIV 2 97.63/250 39.05%
- TopCoder 250 points 19-SRM 153 DIV 1 84.72/250 33.89%
- SRM 387 DIV2 [250]
- SRM 400 DIV2 [250]
- 最小公倍数 SRM 661 Div1 250: MissingLCM
- Where do I store my custom configuration for a BizTalk solution
- Topcoder SRM 652 DIV1 250