cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit d35b65024336b1fed24d3148637951be054a4830
parent 510f47d04834a64ab96c4c2de46df41accf89ee2
Author: superpozycja <anna@superpozycja.net>
Date:   Wed, 23 Oct 2024 21:36:49 +0200

solve permutation

Diffstat:
Aintro/permutations.cpp | 31+++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)

diff --git a/intro/permutations.cpp b/intro/permutations.cpp @@ -0,0 +1,31 @@ +#include <bits/stdc++.h> + +using namespace std; + +void solve() +{ + long n; + cin >> n; + if (n == 1) { + cout << "1\n"; + return; + } + if (n < 4) { + cout << "NO SOLUTION\n"; + return; + } + + for (int i = (n+1)/2; i < n; i++) { + cout << (2-n%2)+(i*2)%n << " "; + } + for (int i = 0; i < (n+1)/2; i++) { + cout << 1+(i*2)%n << " "; + } + + cout << "\n"; +} + +int main() +{ + solve(); +}