Advertisement
ec1117

Untitled

Feb 13th, 2022
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int N,K,A1,A2,B1,B2,res[101];
  6.  
  7. int nex(int x) {
  8.     if (A1 <= x && x <= A2) x = A1+A2-x;
  9.     if (B1 <= x && x <= B2) x = B1+B2-x;
  10.     return x;
  11. }
  12.  
  13. int main() {
  14.     cin >> N >> K >> A1 >> A2 >> B1 >> B2;
  15.     for (int i = 1; i <= N; ++i) {
  16.         int p = 1, cur = nex(i);
  17.         while (cur != i) {
  18.             p ++;
  19.             cur = nex(cur);
  20.         }
  21.         int k = K%p;
  22.         for (int j = 0; j < k; ++j) cur = nex(cur);
  23.         res[cur] = i; // position of cow i after k steps is cur
  24.     }
  25.     for (int i = 1; i <= N; ++i) cout << res[i] << "\n";
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement