mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-05 17:50:36 +00:00
41 lines
897 B
C++
41 lines
897 B
C++
#include <iostream>
|
|
using namespace std;
|
|
|
|
const int N = 1000;
|
|
int c[N];
|
|
|
|
int logic(int x, int y) {
|
|
return (x & y) ^ ((x ^ y) | (~x & y));
|
|
}
|
|
|
|
void generate(int a, int b, int *c) {
|
|
for (int i = 0; i < b; i++)
|
|
c[i] = logic(a, i) % (b + 1);
|
|
}
|
|
|
|
void recursion(int depth, int *arr, int size) {
|
|
if (depth <= 0 || size <= 1) return;
|
|
int pivot = arr[0];
|
|
int i = 0, j = size - 1;
|
|
while (i <= j) {
|
|
while (arr[i] < pivot) i++;
|
|
while (arr[j] > pivot) j--;
|
|
if (i <= j) {
|
|
int temp = arr[i];
|
|
arr[i] = arr[j];
|
|
arr[j] = temp;
|
|
i++; j--;
|
|
}
|
|
}
|
|
recursion(depth - 1, arr, j + 1);
|
|
recursion(depth - 1, arr + i, size - i);
|
|
}
|
|
|
|
int main() {
|
|
int a, b, d;
|
|
cin >> a >> b >> d;
|
|
generate(a, b, c);
|
|
recursion(d, c, b);
|
|
for (int i = 0; i < b; ++i) cout << c[i] << " ";
|
|
cout << endl;
|
|
} |