aboutsummaryrefslogtreecommitdiff
path: root/works/life/chuanzhi-cup
diff options
context:
space:
mode:
Diffstat (limited to 'works/life/chuanzhi-cup')
-rw-r--r--works/life/chuanzhi-cup/.clangd2
-rw-r--r--works/life/chuanzhi-cup/.gitignore1
-rw-r--r--works/life/chuanzhi-cup/README.md1
-rw-r--r--works/life/chuanzhi-cup/contest/1.cpp22
-rw-r--r--works/life/chuanzhi-cup/contest/2.cpp28
-rw-r--r--works/life/chuanzhi-cup/contest/3.cpp46
-rw-r--r--works/life/chuanzhi-cup/contest/4.cpp48
-rw-r--r--works/life/chuanzhi-cup/final-contest/1.cpp32
-rw-r--r--works/life/chuanzhi-cup/final-contest/2.cpp29
-rw-r--r--works/life/chuanzhi-cup/final-contest/3.cpp38
-rw-r--r--works/life/chuanzhi-cup/final-contest/4.cpp86
-rw-r--r--works/life/chuanzhi-cup/final-contest/5.cpp48
-rw-r--r--works/life/chuanzhi-cup/practice-contest/1.cpp27
-rw-r--r--works/life/chuanzhi-cup/practice-contest/2.cpp30
-rw-r--r--works/life/chuanzhi-cup/practice-contest/3.cpp38
-rw-r--r--works/life/chuanzhi-cup/practice-contest/4.cpp47
16 files changed, 523 insertions, 0 deletions
diff --git a/works/life/chuanzhi-cup/.clangd b/works/life/chuanzhi-cup/.clangd
new file mode 100644
index 0000000..d31be00
--- /dev/null
+++ b/works/life/chuanzhi-cup/.clangd
@@ -0,0 +1,2 @@
+CompileFlags:
+ Add: [-std=c++17] \ No newline at end of file
diff --git a/works/life/chuanzhi-cup/.gitignore b/works/life/chuanzhi-cup/.gitignore
new file mode 100644
index 0000000..1feae78
--- /dev/null
+++ b/works/life/chuanzhi-cup/.gitignore
@@ -0,0 +1 @@
+*.exe
diff --git a/works/life/chuanzhi-cup/README.md b/works/life/chuanzhi-cup/README.md
new file mode 100644
index 0000000..5fb89b7
--- /dev/null
+++ b/works/life/chuanzhi-cup/README.md
@@ -0,0 +1 @@
+此文件夹下是我参加传智杯写的垃圾代码。
diff --git a/works/life/chuanzhi-cup/contest/1.cpp b/works/life/chuanzhi-cup/contest/1.cpp
new file mode 100644
index 0000000..4a20d97
--- /dev/null
+++ b/works/life/chuanzhi-cup/contest/1.cpp
@@ -0,0 +1,22 @@
+#include <cstdio>
+
+int main() {
+ int n, v, m, a;
+ std::scanf("%d%d%d%d", &n, &v, &m, &a);
+
+ int money = 0;
+
+ v -= a;
+
+ for (int i = 0; i < n; i++) {
+ if (i % m == 0) {
+ v += a;
+ }
+
+ money += v;
+ }
+
+ std::printf("%d", money);
+
+ return 0;
+} \ No newline at end of file
diff --git a/works/life/chuanzhi-cup/contest/2.cpp b/works/life/chuanzhi-cup/contest/2.cpp
new file mode 100644
index 0000000..358e7fc
--- /dev/null
+++ b/works/life/chuanzhi-cup/contest/2.cpp
@@ -0,0 +1,28 @@
+#include <cmath>
+#include <cstdio>
+
+int main() {
+ int x;
+ std::scanf("%d", &x);
+
+ double gpa;
+
+ if (x >= 90)
+ gpa = 4.0;
+ else if (x >= 60) {
+ gpa = (x - 50.0) / 10.0;
+ } else {
+ int s = std::floor(std::sqrt(x) * 10.0);
+ if (s >= 90)
+ gpa = 4.0;
+ else if (s >= 60) {
+ gpa = (s - 50.0) / 10.0;
+ } else {
+ gpa = 0;
+ }
+ }
+
+ std::printf("%.1f", gpa);
+
+ return 0;
+} \ No newline at end of file
diff --git a/works/life/chuanzhi-cup/contest/3.cpp b/works/life/chuanzhi-cup/contest/3.cpp
new file mode 100644
index 0000000..8f0769d
--- /dev/null
+++ b/works/life/chuanzhi-cup/contest/3.cpp
@@ -0,0 +1,46 @@
+#include <cstdio>
+#include <set>
+
+struct V {
+ V(int n, int t, int k) : n(n), t(t), k(k), c(t * k) {}
+
+ int n;
+ int t;
+ int k;
+ const int c;
+};
+
+struct C {
+ bool operator()(const V &left, const V &right) const {
+ if (left.c > right.c)
+ return true;
+ else if (left.c < right.c)
+ return false;
+ else if (left.t > right.t)
+ return true;
+ else if (left.t < right.t)
+ return false;
+ else if (left.n < right.n)
+ return true;
+ return false;
+ }
+};
+
+int main() {
+ std::set<V, C> data;
+
+ int n;
+ std::scanf("%d", &n);
+
+ for (int i = 1; i <= n; i++) {
+ int t, k;
+ std::scanf("%d%d", &t, &k);
+ data.insert(V{i, t, k});
+ }
+
+ for (const auto &v : data) {
+ std::printf("%d ", v.n);
+ }
+
+ return 0;
+} \ No newline at end of file
diff --git a/works/life/chuanzhi-cup/contest/4.cpp b/works/life/chuanzhi-cup/contest/4.cpp
new file mode 100644
index 0000000..da01a23
--- /dev/null
+++ b/works/life/chuanzhi-cup/contest/4.cpp
@@ -0,0 +1,48 @@
+#include <algorithm>
+#include <cstdio>
+#include <iostream>
+#include <string>
+#include <vector>
+
+int main() {
+ std::vector<std::string> files;
+ int n;
+ std::cin >> n;
+ int current_count = 0;
+ while (current_count < n) {
+ std::string command;
+ std::cin >> command;
+ char a = command[0];
+ if (a == 't') {
+ std::string file;
+ std::cin >> file;
+ auto iter = std::find(files.cbegin(), files.cend(), file);
+ if (iter == files.cend()) {
+ files.push_back(std::move(file));
+ }
+ } else if (a == 'l') {
+ for (const auto &f : files) {
+ std::cout << f << '\n';
+ }
+ } else {
+ char b = command[1];
+ if (b == 'm') {
+ std::string file;
+ auto iter = std::find(files.cbegin(), files.cend(), file);
+ if (iter != files.cend())
+ files.erase(iter);
+ } else {
+ std::string old, new_f;
+ std::cin >> old >> new_f;
+ auto iter = std::find(files.begin(), files.end(), old);
+ auto iter2 = std::find(files.begin(), files.end(), new_f);
+ if (iter != files.end() && iter2 == files.end()) {
+ *iter = std::move(new_f);
+ }
+ }
+ }
+ current_count++;
+ }
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/final-contest/1.cpp b/works/life/chuanzhi-cup/final-contest/1.cpp
new file mode 100644
index 0000000..ad95603
--- /dev/null
+++ b/works/life/chuanzhi-cup/final-contest/1.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+#include <unordered_set>
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ int n, m;
+ std::cin >> n >> m;
+
+ std::unordered_set<int> a;
+
+ for (int i = 0; i < n; i++) {
+ int j;
+ std::cin >> j;
+ a.insert(j);
+ }
+
+ int count = 0;
+
+ for (int i = 0; i < m; i++) {
+ int j;
+ std::cin >> j;
+ if (a.count(j)) {
+ count++;
+ }
+ }
+
+ std::cout << count;
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/final-contest/2.cpp b/works/life/chuanzhi-cup/final-contest/2.cpp
new file mode 100644
index 0000000..6e65576
--- /dev/null
+++ b/works/life/chuanzhi-cup/final-contest/2.cpp
@@ -0,0 +1,29 @@
+#include <iostream>
+
+long long a[1010];
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ int n, k;
+ std::cin >> n >> k;
+
+ for (int i = 0; i < n; i++) {
+ std::cin >> a[i];
+ }
+
+ long long count = 0;
+
+ for (int i = 0; i < n; i++) {
+ for (int j = i + 1; j < n; j++) {
+ if (a[i] * a[j] <= k) {
+ count++;
+ }
+ }
+ }
+
+ std::cout << count;
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/final-contest/3.cpp b/works/life/chuanzhi-cup/final-contest/3.cpp
new file mode 100644
index 0000000..288e011
--- /dev/null
+++ b/works/life/chuanzhi-cup/final-contest/3.cpp
@@ -0,0 +1,38 @@
+#include <cctype>
+#include <iostream>
+#include <string>
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ int T;
+ std::cin >> T;
+
+ for (int i = 0; i < T; i++) {
+ int _a, _b;
+ std::cin >> _a >> _b;
+ std::string a, b;
+ std::cin >> a >> b;
+
+ for (char &c : a) {
+ c = std::tolower(c);
+ }
+
+ for (char &c : b) {
+ c = std::tolower(c);
+ }
+
+ int count = 0;
+
+ for (int i = 0; i < b.size() - a.size() + 1; i++) {
+ if (a == b.substr(i, a.size())) {
+ count++;
+ }
+ }
+
+ std::cout << count << "\n";
+ }
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/final-contest/4.cpp b/works/life/chuanzhi-cup/final-contest/4.cpp
new file mode 100644
index 0000000..19c66d3
--- /dev/null
+++ b/works/life/chuanzhi-cup/final-contest/4.cpp
@@ -0,0 +1,86 @@
+#include <iostream>
+#include <map>
+
+std::map<int, int> c[3];
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ int n, m;
+
+ std::cin >> n >> m;
+
+ for (int i = 0; i < 3; i++) {
+ auto &cc = c[i];
+ for (int j = 0; j < n; j++) {
+ int k;
+ std::cin >> k;
+ cc[k]++;
+ }
+ }
+
+ int current = 0;
+ std::pair<int, int> last;
+ int last_put = 0;
+
+ while (true) {
+ auto &cc = c[current];
+
+ if (current == last_put) {
+ auto i = cc.begin();
+ last.first = i->first;
+ last.second = 1;
+ if (i->second == 1) {
+ cc.erase(i);
+ } else {
+ i->second--;
+ }
+ last_put = current;
+ } else {
+ bool can = false;
+
+ for (auto i = cc.upper_bound(last.first); i != cc.end(); ++i) {
+ if (i->second >= last.second) {
+ can = true;
+ i->second -= last.second;
+ last.first = i->first;
+ if (i->second == 0) {
+ cc.erase(i);
+ }
+ break;
+ }
+ }
+
+ if (!can) {
+ auto end = cc.upper_bound(last.first);
+ for (auto i = cc.begin(); i != end; ++i) {
+ if (i->second > last.second) {
+ can = true;
+ i->second -= last.second + 1;
+ last.first = i->first;
+ last.second++;
+ if (i->second == 0) {
+ cc.erase(i);
+ }
+ break;
+ }
+ }
+ }
+
+ if (can) {
+ last_put = current;
+ }
+ }
+
+ if (cc.empty()) {
+ std::cout << current + 1;
+ break;
+ }
+
+ current++;
+ current %= 3;
+ }
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/final-contest/5.cpp b/works/life/chuanzhi-cup/final-contest/5.cpp
new file mode 100644
index 0000000..a2707c0
--- /dev/null
+++ b/works/life/chuanzhi-cup/final-contest/5.cpp
@@ -0,0 +1,48 @@
+#include <algorithm>
+#include <iostream>
+
+int n, m;
+int w[100010];
+int c[100010];
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ std::cin >> n >> m;
+
+ for (int i = 0; i < n; i++) {
+ std::cin >> w[i];
+ }
+
+ for (int i = 0; i < m; i++) {
+ std::cin >> c[i];
+ }
+
+ std::sort(w, w + n);
+ std::sort(c, c + m);
+
+ int a = 0, b = 0;
+ int count = 0;
+
+ while (true) {
+ if (a == n) {
+ break;
+ }
+ if (b == m) {
+ break;
+ }
+
+ if (w[a] >= c[b]) {
+ a++;
+ b++;
+ count++;
+ } else {
+ a++;
+ }
+ }
+
+ std::cout << count;
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/practice-contest/1.cpp b/works/life/chuanzhi-cup/practice-contest/1.cpp
new file mode 100644
index 0000000..1a0d88e
--- /dev/null
+++ b/works/life/chuanzhi-cup/practice-contest/1.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+
+int main() {
+ int n;
+ std::cin >> n;
+
+ int count = 0;
+
+ for (int i = 1; i <= n; i++) {
+ int num = i;
+ int sum = 0;
+ while (num != 0) {
+ sum += num % 10;
+ num /= 10;
+
+ if (sum > 9)
+ break;
+ }
+
+ if (sum == 9)
+ count++;
+ }
+
+ std::cout << count;
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/practice-contest/2.cpp b/works/life/chuanzhi-cup/practice-contest/2.cpp
new file mode 100644
index 0000000..5622eb4
--- /dev/null
+++ b/works/life/chuanzhi-cup/practice-contest/2.cpp
@@ -0,0 +1,30 @@
+#include <iostream>
+
+long long sqrt(long long num) {
+ long long left = 1, right = num;
+ while (left != right) {
+ long long mid = (left + right) / 2;
+ if (mid * mid < num) {
+ left = mid + 1;
+ } else {
+ right = mid;
+ }
+ }
+ return left;
+}
+
+int main() {
+ long long c;
+ std::cin >> c;
+
+ for (long long i = 1; i < c; i++) {
+ long long b2 = c * c - i * i;
+ long long b = sqrt(b2);
+ if (b * b == b2) {
+ std::cout << i << " " << b;
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/practice-contest/3.cpp b/works/life/chuanzhi-cup/practice-contest/3.cpp
new file mode 100644
index 0000000..1f79723
--- /dev/null
+++ b/works/life/chuanzhi-cup/practice-contest/3.cpp
@@ -0,0 +1,38 @@
+#include <cmath>
+#include <iomanip>
+#include <iostream>
+#include <regex>
+#include <string>
+
+int main() {
+ std::string input;
+ std::getline(std::cin, input);
+
+ std::regex reg(R"aaa((\d+)([GMK]?B)=\?([GMK]?B))aaa");
+ std::smatch match;
+ std::regex_match(input, match, reg);
+
+ std::string original_number_str = match[1].str();
+ std::string original_unit = match[2].str();
+ std::string target_unit = match[3].str();
+
+ double original_number = std::stod(original_number_str);
+
+ auto to_ratio = [](const std::string s) -> double {
+ if (s.size() == 1)
+ return 1;
+ if (s[0] == 'G')
+ return std::pow(2, 30);
+ if (s[0] == 'M')
+ return std::pow(2, 20);
+ return std::pow(2, 10);
+ };
+
+ double original_ratio = to_ratio(original_unit);
+ double target_ratio = to_ratio(target_unit);
+
+ std::cout << std::fixed << std::setprecision(6)
+ << (original_number * original_ratio / target_ratio);
+
+ return 0;
+}
diff --git a/works/life/chuanzhi-cup/practice-contest/4.cpp b/works/life/chuanzhi-cup/practice-contest/4.cpp
new file mode 100644
index 0000000..bab6b2d
--- /dev/null
+++ b/works/life/chuanzhi-cup/practice-contest/4.cpp
@@ -0,0 +1,47 @@
+#include <algorithm>
+#include <iomanip>
+#include <iostream>
+
+int score[1000001];
+double result[1000001];
+
+int main() {
+ int min;
+ int max;
+ int sum = 0;
+
+ int count;
+ std::cin >> count;
+
+ for (int i = 1; i <= count; i++) {
+ std::cin >> score[i];
+ }
+
+ int n1 = score[1], n2 = score[2];
+ sum += n1 + n2;
+ min = std::min(n1, n2);
+ max = std::max(n1, n2);
+
+ for (int i = 3; i <= count; i++) {
+ int current = score[i];
+
+ min = std::min(current, min);
+ max = std::max(current, max);
+
+ sum += current;
+
+ int s = sum;
+ s -= min;
+ s -= max;
+
+ result[i] = static_cast<double>(s) / (i - 2);
+ }
+
+ std::cout << std::fixed << std::setprecision(2);
+
+ for (int i = 3; i <= count; i++) {
+ std::cout << result[i] << "\n";
+ }
+
+ return 0;
+}