diff --git a/src/test.cpp b/src/test.cpp index d5ad936..de5a8d6 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1,22 +1,41 @@ #include -#include -#include +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() { - // 降序序列 - std::vector nums = {9, 7, 5, 3, 1}; - int x = 4; - - // 使用upper_bound查找第一个比x大的元素 - // 第三个参数是目标值x - // 第四个参数是自定义比较函数,保持降序的比较逻辑 - auto it = std::upper_bound(nums.begin(), nums.end(), x, std::greater()); - - if (it != nums.end()) { - std::cout << "第一个比" << x << "大的数是: " << *it << std::endl; - } else { - std::cout << "没有比" << x << "大的数" << std::endl; - } - - return 0; + 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; } \ No newline at end of file