From 711f39698cb9f691ece3d92a3a25f45f3e6122a4 Mon Sep 17 00:00:00 2001 From: cnhacklqr Date: Thu, 25 Jan 2024 18:07:29 +0800 Subject: [PATCH] Update Code --- src/algorithm/fenzhi/jiaoyouhuodong.cpp | 42 +++++++++++++++++++++++++ src/algorithm/fenzhi/mod.cpp | 32 +++++++++---------- 2 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 src/algorithm/fenzhi/jiaoyouhuodong.cpp diff --git a/src/algorithm/fenzhi/jiaoyouhuodong.cpp b/src/algorithm/fenzhi/jiaoyouhuodong.cpp new file mode 100644 index 0000000..a6dfd36 --- /dev/null +++ b/src/algorithm/fenzhi/jiaoyouhuodong.cpp @@ -0,0 +1,42 @@ +#include +#define MAXN 1000000 + +bool check(int n, int nn, int *C, int *M, int A) { + int count = 0, i, j; + i = nn; + j = 1; + while (i <= n) { + if (M[i] < C[j]) { + count += C[j] - M[i]; + } + i++; + j++; + } + return count <= A; +} + +int main() { + int n, M[MAXN], C[MAXN], mid, ans, B, A; + std::cin >> n >> B >> A; // N:Students B:Bike Nums A:School Money M:Student + // Money C:Student Bike Money + for (int i = 1; i <= n; i++) { + std::cin >> M[i]; + } + for (int i = 1; i <= n; i++) { + std::cin >> C[i]; + } + // sort() + // sort() + int l = 0, r = n; + while (l <= r) { + mid = (l + r) / 2; + if (check(n, mid, C, M, A)) { + ans = mid; + l = mid + 1; + } else { + r = mid - 1; + } + } + std::cout << ans << std::endl; + return 0; +} diff --git a/src/algorithm/fenzhi/mod.cpp b/src/algorithm/fenzhi/mod.cpp index 84790c2..d4c94fb 100644 --- a/src/algorithm/fenzhi/mod.cpp +++ b/src/algorithm/fenzhi/mod.cpp @@ -1,22 +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; + 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 + int b, p, k; + std::cin >> b >> p >> k; + int tmpb = b; + b %= k; + std::cout << f(p, k, b) << std::endl; + return 0; +}