From d4909489d0b6d6e9d5c5b4eff6e373a8ad396591 Mon Sep 17 00:00:00 2001 From: KIRTIKUMARKK21 Date: Wed, 20 Oct 2021 17:41:05 +0530 Subject: [PATCH] Shifting Sort Added --- codeforces_Solution/ShiftingSort.cpp | 95 ++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 codeforces_Solution/ShiftingSort.cpp diff --git a/codeforces_Solution/ShiftingSort.cpp b/codeforces_Solution/ShiftingSort.cpp new file mode 100644 index 0000000..5dc86bd --- /dev/null +++ b/codeforces_Solution/ShiftingSort.cpp @@ -0,0 +1,95 @@ +// https://codeforces.com/problemset/problem/1579/B + + +#include +using namespace std; +#define PI 3.1415926535897932384626433832795 +#define MOD 1000000007 +#define pb push_back +#define rep(i,a,b) for(int i=a;i +#define vi vector +#define lb lower_bound +#define ub upper_bound +#define print(ans) printf("%.9f\n",ans) +#define all(x) (x).begin(), (x).end() +typedef int64_t ll; +typedef unsigned long long ull; +typedef long double lld; +#define pi pair +#define nline "\n" +int rotate(vector&v) +{ + int mi = INT_MAX; + int idx = 1; + int n = v.size(); + rep(i, 1, n) + { + if (v[i] < mi) + { + mi = v[i]; + idx = i; + } + } + vectortemp; + temp.pb(0); + rep(i, idx + 1, n) + { + temp.pb(v[i]); + } + rep(i, 1, idx) + { + temp.pb(v[i]); + } + v = temp; + return idx; + +} +void solve() +{ + int n; + cin >> n; + vectorv; + v.pb(0); + rep(i, 0, n) + { + int a; + cin >> a; + v.pb(a); + } + vector, int>>ans; + rep(i, 1, n + 1) + { + int d = rotate(v); + d--; + if (d != 0) + { + ans.pb({{i, n}, d}); + } + } + cout << ans.size() << nline; + for (auto it : ans) + { + cout << it.first.first << " " << it.first.second << " " << it.second << nline; + } + + +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); +#ifndef ONLINE_JUDGE + freopen("input.in", "r", stdin); + freopen("output.out", "w", stdout); + freopen("Error.out", "w", stderr); +#endif + int t; + cin >> t; + while (t--) + { + solve(); + } + return 0; +}