-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminsort.cpp
55 lines (45 loc) · 853 Bytes
/
minsort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
int n;
int minq(int i, int j) {
i++, j++;
int ans;
cout << "M " << i << " " << j << endl;
cin >> ans;
return ans - 1;
}
void swapq(int i, int j) {
i++, j++;
if (i == j) return;
int ans;
cout << "S " << i << " " << j << endl;
cin >> ans;
assert(ans == 1);
return;
}
void done() {
int ans;
cout << "D" << endl;
cin >> ans;
assert(ans == 1);
return;
}
void solve() {
// for a solve get the min and put it to the front
for (int i = 0; i < n - 1; i++) {
int curr_min = minq(i, n - 1);
swapq(i, curr_min);
}
done();
}
int main() {
int t;
cin >> t >> n;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}