Updatec Code

This commit is contained in:
Hmtsai 2024-01-25 12:06:03 +08:00
parent 9f7ff04c9d
commit 812e0560da
9 changed files with 113 additions and 21 deletions

View File

@ -1,4 +1,3 @@
#include <ios>
#include <iostream> #include <iostream>
class stack { class stack {

View File

@ -0,0 +1,15 @@
#include <iostream>
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);
}

View File

@ -1,27 +1,35 @@
#include <bits/stdc++.h>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
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 main() {
int n, m; int m;
std::cin >> m; std::cin >> m;
int size = std::pow(2, m) + 1; int size = std::pow(2, m) + 1;
int arr[size][size]; for (int i = 1; !(i > size - 1); i++) {
for (int i = 0; i <= size; i++) { for (int j = 1; !(j > size - 1); j++) {
for (auto &j : arr[i]) { arr[i][j] = 0;
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);
}
}
} }
} }
compute(size - 1);
for (int i = 1; i < size; i++) { for (int i = 1; i < size; i++) {
for (int j = 1; j < size; j++) { for (int j = 1; j < size; j++) {
std::cout << arr[i][j] << " "; std::cout << arr[i][j] << " ";

BIN
src/algorithm/fenzhi/mod Executable file

Binary file not shown.

View File

@ -0,0 +1,22 @@
#include <iostream>
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;
}

Binary file not shown.

View File

@ -0,0 +1,48 @@
#include <algorithm>
#include <iostream>
#include <variant>
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;
}

View File

@ -21,18 +21,18 @@ int partition(int *arr, int low, int high) {
return i; return i;
} }
void quickSort(int *arr, int low, int high) { void qSort(int *arr, int low, int high) {
int mid; int mid;
if (low < high) { if (low < high) {
mid = partition(arr, low, high); mid = partition(arr, low, high);
quickSort(arr, low, mid - 1); qSort(arr, low, mid - 1);
quickSort(arr, mid + 1, high); qSort(arr, mid + 1, high);
} }
} }
int main() { int main() {
int a[] = {57, 68, 59, 52, 72, 28, 98, 33, 24}; 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) { for (int i : a) {
std::cout << i << " "; std::cout << i << " ";
} }