1 #include <iostream> 2 #include <sstream> 3 #include <string> 4 #include <algorithm> 5 #include <vector> 6 using namespace std; 7 8 #define GI ({int _t; scanf("%d", &_t); _t;}) 9 #define FOR(i, a, b) for (int i=a; i<b; i++) 10 #define REP(i, a) FOR(i, 0, a) 11 template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();} 12 int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} 13 #define DBGV(_v) { REP(_i, _v.size()) { cout << _v[_i] << "\t";} cout << endl;} 14 15 int main() { 16 int cnt = GI; 17 while (cnt--) { 18 int num = GI; 19 vector <int> nums (num, 0); 20 REP(i, num) { 21 nums[i] = GI; 22 } 23 int swaps = 0; 24 REP(i, num) { 25 FOR(j, i+1, num) { 26 if (nums[i] > nums[j]) { 27 swaps++; 28 swap(nums[i], nums[j]); 29 } 30 } 31 } 32 printf("Optimal train swapping takes %d swaps.\n", swaps); 33 } 34 return 0; 35 }