diff --git a/src/algorithm/digui/jinzhizhuanhuan.cpp b/src/algorithm/digui/jinzhizhuanhuan.cpp index 38925e4..7d2644b 100644 --- a/src/algorithm/digui/jinzhizhuanhuan.cpp +++ b/src/algorithm/digui/jinzhizhuanhuan.cpp @@ -1,4 +1,3 @@ -#include #include class stack { diff --git a/src/algorithm/digui/while.cpp b/src/algorithm/digui/while.cpp new file mode 100644 index 0000000..8c1f4a0 --- /dev/null +++ b/src/algorithm/digui/while.cpp @@ -0,0 +1,15 @@ +#include + +void inputn(int &n) { std::cin >> n; } +void inputlistn(int n, int *arr) { + inputlistn(n - 1, arr); + std::cin >> arr[n]; +} + +int main() { + int n, *listn; + inputn(n); + listn = new int[n]; + inputlistn(n, listn); + +} \ No newline at end of file diff --git a/src/algorithm/fenzhi/mianxiangjieguobiancheng b/src/algorithm/fenzhi/mianxiangjieguobiancheng index 36a5b7f..64b3923 100755 Binary files a/src/algorithm/fenzhi/mianxiangjieguobiancheng and b/src/algorithm/fenzhi/mianxiangjieguobiancheng differ diff --git a/src/algorithm/fenzhi/mianxiangjieguobiancheng.cpp b/src/algorithm/fenzhi/mianxiangjieguobiancheng.cpp index 57960b1..a5ea55c 100644 --- a/src/algorithm/fenzhi/mianxiangjieguobiancheng.cpp +++ b/src/algorithm/fenzhi/mianxiangjieguobiancheng.cpp @@ -1,27 +1,35 @@ +#include #include #include +int arr[100][100]; + +void compute(int n) { + if (n == 0) { + arr[1][1] = 1; + return; + } + compute(n / 2); + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + arr[i][j + n] = arr[i][j] + n; + arr[i + n][j] = arr[i][j] + n; + arr[i + n][j + n] = arr[i][j]; + } + } + return; +} + int main() { - int n, m; + int m; std::cin >> m; int size = std::pow(2, m) + 1; - int arr[size][size]; - for (int i = 0; i <= size; i++) { - for (auto &j : arr[i]) { - j = 0; - } - } - for (int i = 0; i < m; i++) { - for (int j = 1; j <= m; j++) { - for (int k = 1; k <= m; k++) { - if (j == 1) { - arr[j + (i * 2)][k + (i * 2)] = k + (i * 2); - } else { - arr[j + (i * 2)][k + (i * 2)] = m - k + 1 + (i * 2); - } - } + for (int i = 1; !(i > size - 1); i++) { + for (int j = 1; !(j > size - 1); j++) { + arr[i][j] = 0; } } + compute(size - 1); for (int i = 1; i < size; i++) { for (int j = 1; j < size; j++) { std::cout << arr[i][j] << " "; diff --git a/src/algorithm/fenzhi/mod b/src/algorithm/fenzhi/mod new file mode 100755 index 0000000..0a3f7ac Binary files /dev/null and b/src/algorithm/fenzhi/mod differ diff --git a/src/algorithm/fenzhi/mod.cpp b/src/algorithm/fenzhi/mod.cpp new file mode 100644 index 0000000..84790c2 --- /dev/null +++ b/src/algorithm/fenzhi/mod.cpp @@ -0,0 +1,22 @@ +#include + +int f(int p, int k, int b) { + if (p == 0) { + return 1; + } + int tmp = f(p / 2, k, b) % k; + tmp = (tmp * tmp) % k; + if (p % 2 == 1) { + tmp = (tmp * b) % k; + } + return tmp; +} + +int main() { + int b, p, k; + std::cin >> b >> p >> k; + int tmpb = b; + b %= k; + std::cout << f(p, k, b) << std::endl; + return 0; +} \ No newline at end of file diff --git a/src/algorithm/fenzhi/shuchuKdadeshu b/src/algorithm/fenzhi/shuchuKdadeshu new file mode 100755 index 0000000..30502c0 Binary files /dev/null and b/src/algorithm/fenzhi/shuchuKdadeshu differ diff --git a/src/algorithm/fenzhi/shuchuKdadeshu.cpp b/src/algorithm/fenzhi/shuchuKdadeshu.cpp new file mode 100644 index 0000000..1f764c7 --- /dev/null +++ b/src/algorithm/fenzhi/shuchuKdadeshu.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +int part(int *arr, int l, int r) { + int i = l, j = r, pir = arr[l]; + while (i < j) { + while (i < j && arr[j] >= pir) { + j--; + } + while (i < j && arr[i] <= pir) { + i++; + } + if (i < j) { + std::swap(arr[i++], arr[j--]); + } + } + if (arr[i] > pir) { + std::swap(arr[i - 1], arr[l]); + return i - 1; + } + std::swap(arr[i], arr[l]); + return i; +} + +void quickSort(int *arr, int l, int r) { + int mid; + if (l < r) { + mid = part(arr, l, r); + quickSort(arr, l, mid - 1); + quickSort(arr, mid + 1, r); + } +} + +int main() { + int n, m; + std::cin >> n >> m; + int listn[n]; + for (int i = 0; i < n; i++) { + std::cin >> listn[i]; + } + quickSort(listn, 0, n); + for (int i = m - 1; i >= 0; i--) { + std::cout << listn[i] << " "; + } + std::cout << std::endl; + return 0; +} \ No newline at end of file diff --git a/src/algorithm/sort/quick/quick(Fixed).cpp b/src/algorithm/sort/quick/quick(Fixed).cpp index 8b218f2..07a1dd7 100644 --- a/src/algorithm/sort/quick/quick(Fixed).cpp +++ b/src/algorithm/sort/quick/quick(Fixed).cpp @@ -21,18 +21,18 @@ int partition(int *arr, int low, int high) { return i; } -void quickSort(int *arr, int low, int high) { +void qSort(int *arr, int low, int high) { int mid; if (low < high) { mid = partition(arr, low, high); - quickSort(arr, low, mid - 1); - quickSort(arr, mid + 1, high); + qSort(arr, low, mid - 1); + qSort(arr, mid + 1, high); } } int main() { int a[] = {57, 68, 59, 52, 72, 28, 98, 33, 24}; - quickSort(a, 0, sizeof(a) / sizeof(a[0]) - 1); + qSort(a, 0, sizeof(a) / sizeof(a[0]) - 1); for (int i : a) { std::cout << i << " "; }