0%

Codeforces Round 744 (Div. 3) B题(tuple和rotate的用法)

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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int T;
ll a[110];

void solve() {
int n;
cin >> n;
queue<tuple<int, int, int> > res;

for(int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
for(int i = 0; i < n; i++) {
int j = min_element(a + i, a + n) - a;
if(i == j) continue;
rotate(a + i, a + j, a + n);
res.push(make_tuple(i, n, j - i));
}
cout << res.size() << "\n";
while (!res.empty()) {
auto&[l, r, d] = res.front();
cout << l+1 << ' ' << r << ' ' << d << '\n';
res.pop();
}

}

int main() {
cin >> T;
while(T--) {
solve();
}

return 0;
}
求大佬赏个饭