From 62f75b25bc917923b1ddf7014efd145b9c57816b Mon Sep 17 00:00:00 2001 From: zhangzc Date: Thu, 28 Oct 2021 16:03:01 +0800 Subject: [PATCH] update exercises --- .../solution.md" | 51 +++++- .../solution.cpp" | 4 +- .../solution.md" | 94 +++++++++- .../solution.md" | 164 +++++++++++++++++- .../solution.md" | 102 ++++++++++- .../solution.md" | 101 ++++++++++- .../solution.md" | 145 +++++++++++++++- .../desc.md" | 7 +- .../solution.md" | 97 ++++++++++- .../solution.md" | 142 ++++++++++++++- .../solution.md" | 81 +++++++++ .../config.json" | 6 - .../desc.md" | 20 --- .../solution.cpp" | 0 .../solution.java" | 24 --- .../solution.md" | 52 ------ .../solution.cpp" | 2 +- .../solution.md" | 114 +++++++++++- .../\346\212\275\347\255\276/solution.md" | 68 +++++++- .../solution.md" | 140 ++++++++++++++- .../solution.md" | 107 +++++++++++- .../solution.md" | 110 +++++++++++- .../solution.md" | 78 ++++++++- .../solution.md" | 80 ++++++++- .../solution.md" | 22 ++- .../solution.cpp" | 64 +++---- .../solution.md" | 83 ++++++++- .../solution.md" | 141 ++++++++++++++- 28 files changed, 1884 insertions(+), 215 deletions(-) delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/config.json" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/desc.md" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.cpp" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.java" delete mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.md" diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" index 4135e0706..2e6c7e134 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" @@ -10,6 +10,9 @@ ### before ```cpp +#include + +using namespace std; ``` ### after ```cpp @@ -18,21 +21,61 @@ ## 答案 ```cpp - +int main() +{ + set s; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) + for (int j = i; j < str.size(); j++) + s.insert(str.substr(i, j - i + 1)); + cout << s.size(); + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + set s; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) + for (int j = i; j < str.size(); j++) + s.insert(str.substr(i, j + i - 1)); + cout << s.size(); + return 0; +} ``` ### B ```cpp - +int main() +{ + set s; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) + for (int j = i; j < str.size(); j++) + s.insert(str.substr(i, j + 1)); + cout << s.size(); + return 0; +} ``` ### C ```cpp - +int main() +{ + set s; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) + for (int j = i; j < str.size(); j++) + s.insert(str.substr(i, j - i)); + cout << s.size(); + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.cpp" index 290e75285..c7dc6ee87 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.cpp" @@ -10,12 +10,12 @@ int main() while (num % 5 == 0) { count5++; - num /= 5; + num += 5; } while (num % 2 == 0) { count2++; - num /= 2; + num += 2; } } int ans = count2 < count5 ? count2 : count5; diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.md" index 53c7e30ce..33d7d34cd 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\345\260\276\351\233\266/solution.md" @@ -16,7 +16,8 @@ ## aop ### before ```cpp - +#include +using namespace std; ``` ### after ```cpp @@ -25,21 +26,106 @@ ## 答案 ```cpp - +int main() +{ + int count2 = 0, count5 = 0; + int num; + for (int i = 0; i < 100; i++) + { + cin >> num; + while (num % 5 == 0) + { + count5++; + num /= 5; + } + while (num % 2 == 0) + { + count2++; + num /= 2; + } + } + int ans = count2 < count5 ? count2 : count5; + cout << ans; + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + int count2 = 0, count5 = 0; + int num; + for (int i = 0; i < 100; i++) + { + cin >> num; + while (num % 5 == 0) + { + count5++; + num /= 5; + } + while (num % 2 == 0) + { + count2++; + num /= 2; + } + } + int ans = count2 < count5 ? count5 : count2; + cout << ans; + return 0; +} ``` ### B ```cpp +int main() +{ + int count2 = 0, count5 = 0; + int num; + for (int i = 0; i < 100; i++) + { + cin >> num; + while (num % 5 == 0) + { + count5++; + num %= 5; + } + while (num % 2 == 0) + { + count2++; + num %= 2; + } + } + int ans = count2 < count5 ? count2 : count5; + cout << ans; + return 0; +} ``` ### C ```cpp - +int main() +{ + int count2 = 0, count5 = 0; + int num; + for (int i = 0; i < 100; i++) + { + cin >> num; + while (num % 5 == 0) + { + count5++; + num += 5; + } + while (num % 2 == 0) + { + count2++; + num += 2; + } + } + int ans = count2 < count5 ? count2 : count5; + cout << ans; + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\346\234\200\345\244\247/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\346\234\200\345\244\247/solution.md" index 8c06bbc07..ab6dea510 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\346\234\200\345\244\247/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\344\271\230\347\247\257\346\234\200\345\244\247/solution.md" @@ -47,7 +47,10 @@ ## aop ### before ```cpp - +#include +#include +#include +using namespace std; ``` ### after ```cpp @@ -56,21 +59,174 @@ ## 答案 ```cpp +int main() +{ + int n, k; + long long ans; + cin >> n >> k; + vector num; + for (int i = 0; i < n; i++) + { + int temp; + cin >> temp; + num.push_back(temp); + } + sort(num.begin(), num.end()); + if (k % 2 != 0) + { + ans = num.back(); + k = k - 1; + num.pop_back(); + } + else + ans = 1; + while (k > 0) + { + if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 2)) + { + ans = ans * num[0] * num[1] % 1000000009; + num.erase(num.begin(), num.begin() + 1); + } + else + { + ans = ans * num.at(num.size() - 1) * num.at(num.size() - 2) % 1000000009; + num.pop_back(); + num.pop_back(); + } + k -= 2; + } + cout << ans; + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + int n, k; + long long ans; + cin >> n >> k; + vector num; + for (int i = 0; i < n; i++) + { + int temp; + cin >> temp; + num.push_back(temp); + } + sort(num.begin(), num.end()); + if (k % 2 != 0) + { + ans = num.back(); + k = k - 1; + num.pop_back(); + } + else + ans = 1; + while (k > 0) + { + if ((num[0] * num[1]) > num.at(num.size()) * num.at(num.size() - 1)) + { + ans = ans * num[0] * num[1] % 1000000009; + num.erase(num.begin(), num.begin() + 1); + } + else + { + ans = ans * num.at(num.size()) * num.at(num.size() - 1) % 1000000009; + num.pop_back(); + num.pop_back(); + } + k -= 2; + } + cout << ans; + return 0; +} ``` ### B ```cpp - +int main() +{ + int n, k; + long long ans; + cin >> n >> k; + vector num; + for (int i = 0; i < n; i++) + { + int temp; + cin >> temp; + num.push_back(temp); + } + sort(num.begin(), num.end()); + if (k % 2 != 0) + { + ans = num.back(); + k = k - 1; + num.pop_back(); + } + else + ans = 1; + while (k > 0) + { + if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 1)) + { + ans = ans * num[0] * num[1] % 1000000009; + num.erase(num.begin(), num.begin() + 1); + } + else + { + ans = ans * num.at(num.size() - 1) % 1000000009; + num.pop_back(); + num.pop_back(); + } + k -= 2; + } + cout << ans; + return 0; +} ``` ### C ```cpp - +int main() +{ + int n, k; + long long ans; + cin >> n >> k; + vector num; + for (int i = 0; i < n; i++) + { + int temp; + cin >> temp; + num.push_back(temp); + } + sort(num.begin(), num.end()); + if (k % 2 != 0) + { + ans = num.back(); + k = k - 1; + num.pop_back(); + } + else + ans = 1; + while (k > 0) + { + if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 2)) + { + ans = ans * num[0] * num[1] % 1000000009; + num.erase(num.begin(), num.begin() + 1); + } + else + { + ans = ans * num.at(num.size() - 1) % 1000000009; + num.pop_back(); + num.pop_back(); + } + k -= 2; + } + cout << ans; + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\207\221\347\256\227\345\274\217/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\207\221\347\256\227\345\274\217/solution.md" index ca11e752f..498799b85 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\207\221\347\256\227\345\274\217/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\207\221\347\256\227\345\274\217/solution.md" @@ -16,30 +16,124 @@ A + —- + ——–- = 10 ## aop ### before ```cpp +#include +#include +int ans = 0; +int nums[10]; +bool visited[10]; + +void judge() +{ + int i; + if (nums[0] + (double)nums[1] / nums[2] + (double)(nums[3] * 100 + nums[4] * 10 + nums[5]) / (nums[6] * 100 + nums[7] * 10 + nums[8]) == 10) + { + printf("%d + %d/%d + %d%d%d/%d%d%d", nums[0], nums[1], nums[2], nums[3], nums[4], nums[5], nums[6], nums[7], nums[8]); + printf("\n"); + ans++; + } +} ``` ### after ```cpp +int main() +{ + dfs(0); + printf("%d\n", ans); + return 0; +} ``` ## 答案 ```cpp - +void dfs(int index) +{ + if (index >= 9) + { + judge(); + return; + } + int i; + for (i = 1; i < 10; i++) + { + if (visited[i] == false) + { + visited[i] = true; + nums[index] = i; + dfs(index + 1); + visited[i] = false; + } + } +} ``` ## 选项 ### A ```cpp - +void dfs(int index) +{ + if (index >= 9) + { + judge(); + return; + } + int i; + for (i = 1; i < 10; i++) + { + if (visited[i] == false) + { + visited[i] = true; + nums[index] = i; + dfs(index); + visited[i] = false; + } + } +} ``` ### B ```cpp - +void dfs(int index) +{ + if (index >= 9) + { + judge(); + return; + } + int i; + for (i = 1; i < 10; i++) + { + if (visited[i] == true) + { + visited[i] = false; + nums[index] = i; + dfs(index); + visited[i] = true; + } + } +} ``` ### C ```cpp - +void dfs(int index) +{ + if (index >= 9) + { + judge(); + return; + } + int i; + for (i = 1; i < 10; i++) + { + if (visited[i] == true) + { + visited[i] = false; + nums[index] = i; + dfs(index + 1); + visited[i] = true; + } + } +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\346\225\260\344\271\230\346\263\225/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\346\225\260\344\271\230\346\263\225/solution.md" index 263e44c85..09d02398a 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\346\225\260\344\271\230\346\263\225/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\346\225\260\344\271\230\346\263\225/solution.md" @@ -1,37 +1,134 @@ # 大数乘法 对于32位字长的机器,大约超过20亿,用int类型就无法表示了,我们可以选择int64类型,但无论怎样扩展,固定的整数类型总是有表达的极限!如果对超级大整数进行精确运算呢?一个简单的办法是:仅仅使用现有类型,但是把大整数的运算化解为若干小整数的运算,即所谓:“分块法”。 -![](https://img-blog.csdn.net/20160125091111485) +![](https: 上图表示了分块乘法的原理。可以把大数分成多段(此处为2段)小数,然后用小数的多次运算组合表示一个大数。可以根据int的承载能力规定小块的大小,比如要把int分成2段,则小块可取10000为上限值。注意,小块在进行纵向累加后,需要进行进位校正。 ## aop ### before ```cpp - +#include ``` ### after ```cpp +int main(int argc, char *argv[]) +{ + int x[] = {0, 0, 0, 0}; + + bigmul(87654321, 12345678, x); + + printf("%d%d%d%d\n", x[0], x[1], x[2], x[3]); + return 0; +} ``` ## 答案 ```cpp +void bigmul(int x, int y, int r[]) +{ + int base = 10000; + int x2 = x / base; + int x1 = x % base; + int y2 = y / base; + int y1 = y % base; + int n1 = x1 * y1; + int n2 = x1 * y2; + int n3 = x2 * y1; + int n4 = x2 * y2; + + r[3] = n1 % base; + r[2] = n1 / base + n2 % base + n3 % base; + r[1] = n2 / base + n3 / base + n4 % base; + r[0] = n4 / base; + + r[1] += r[2] / base; + r[2] = r[2] % base; + r[0] += r[1] / base; + r[1] = r[1] % base; +} ``` ## 选项 ### A ```cpp +void bigmul(int x, int y, int r[]) +{ + int base = 10000; + int x2 = x / base; + int x1 = x % base; + int y2 = y / base; + int y1 = y % base; + + int n1 = x1 * y1; + int n2 = x1 * y2; + int n3 = x2 * y1; + int n4 = x2 * y2; + r[3] = n1 % base; + r[2] = n1 / base + n2 % base + n3 % base; + r[1] = n2 / base + n3 / base + n4 % base; + r[0] = n4 / base; + + r[1] += r[2] % base; + r[2] = r[2] / base; + r[0] += r[1] / base; + r[1] = r[1] % base; +} ``` ### B ```cpp +void bigmul(int x, int y, int r[]) +{ + int base = 10000; + int x2 = x / base; + int x1 = x % base; + int y2 = y / base; + int y1 = y % base; + + int n1 = x1 * y1; + int n2 = x1 * y2; + int n3 = x2 * y1; + int n4 = x2 * y2; + + r[3] = n1 % base; + r[2] = n1 / base + n2 % base + n3 % base; + r[1] = n2 / base + n3 / base + n4 / base; + r[0] = n4 / base; + r[1] += r[2] / base; + r[2] = r[2] % base; + r[0] += r[1] / base; + r[1] = r[1] % base; +} ``` ### C ```cpp +void bigmul(int x, int y, int r[]) +{ + int base = 10000; + int x2 = x / base; + int x1 = x % base; + int y2 = y / base; + int y1 = y % base; + + int n1 = x1 * y1; + int n2 = x1 * y2; + int n3 = x2 * y1; + int n4 = x2 * y2; + + r[3] = n1 % base; + r[2] = n1 / base + n2 % base + n3 % base; + r[1] = n2 / base + n3 % base + n4 / base; + r[0] = n4 / base; + r[1] += r[2] / base; + r[2] = r[2] % base; + r[0] += r[1] / base; + r[1] = r[1] % base; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\350\207\243\347\232\204\346\227\205\350\264\271/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\350\207\243\347\232\204\346\227\205\350\264\271/solution.md" index 0a6ba9018..64101b344 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\350\207\243\347\232\204\346\227\205\350\264\271/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\244\247\350\207\243\347\232\204\346\227\205\350\264\271/solution.md" @@ -42,30 +42,165 @@ J大臣想知道:他从某一个城市出发,中间不休息,到达另一 ## aop ### before ```cpp - +#include +using namespace std; +#define mem(a, b) memset(a, b, sizeof(a)) +#define ll long long +const double eps = 3e-8; +const int mod = 10; +const int maxn = 10005; +vector ed[maxn]; +ll edge[maxn][maxn]; +ll dis[maxn]; +ll sum = 0; ``` ### after ```cpp +int main() +{ + int n, a, b; + ll c; + scanf("%d", &n); + for (int i = 1; i < n; i++) + { + scanf("%d%d%lld", &a, &b, &c); + ed[a].push_back(b); + ed[b].push_back(a); + edge[a][b] = c; + edge[b][a] = c; + } + int starta = 1; + int endnode, startnode; + sum = 0; + endnode = bfs(starta); + sum = 0; + startnode = bfs(endnode); + + double ans = sum * (sum + 1.0) / 2 + 10.0 * sum; + printf("%.0f\n", ans); +} ``` ## 答案 ```cpp - +int bfs(int node) +{ + mem(dis, -1); + queue que; + que.push(node); + int ans = node; + dis[node] = 0; + while (!que.empty()) + { + int now = que.front(); + que.pop(); + for (int i = 0; i < ed[now].size(); i++) + { + int temp = ed[now][i]; + if (dis[temp] < 0) + { + dis[temp] = dis[now] + edge[now][temp]; + if (dis[temp] > sum) + { + ans = temp; + sum = dis[temp]; + } + que.push(temp); + } + } + } + return ans; +} ``` ## 选项 ### A ```cpp - +int bfs(int node) +{ + mem(dis, -1); + queue que; + que.push(node); + int ans = node; + dis[node] = 0; + while (!que.empty()) + { + int now = que.front(); + que.pop(); + for (int i = 0; i < ed[now].size(); i++) + { + int temp = ed[now][i]; + if (dis[temp] < 0) + { + dis[temp] = dis[now] + edge[now][temp]; + ans = temp; + sum = dis[temp]; + que.push(temp); + } + } + } + return ans; +} ``` ### B ```cpp - +int bfs(int node) +{ + mem(dis, -1); + queue que; + que.push(node); + int ans = node; + dis[node] = 0; + while (!que.empty()) + { + int now = que.front(); + que.pop(); + for (int i = 0; i < ed[now].size(); i++) + { + int temp = ed[now][i]; + + dis[temp] = dis[now] + edge[now][temp]; + + ans = temp; + sum = dis[temp]; + + que.push(temp); + } + } + return ans; +} ``` ### C ```cpp - +int bfs(int node) +{ + mem(dis, -1); + queue que; + que.push(node); + int ans = node; + dis[node] = 0; + while (!que.empty()) + { + int now = que.front(); + que.pop(); + for (int i = 0; i < ed[now].size(); i++) + { + int temp = ed[now][i]; + if (dis[temp] < 0) + { + dis[temp] = dis[now] + edge[now][temp]; + if (dis[temp] < sum) + { + ans = temp; + sum = dis[temp]; + } + que.push(temp); + } + } + } + return ans; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/desc.md" index 27ba14a7f..217cee459 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/desc.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/desc.md" @@ -1,12 +1,12 @@ #### 问题描述 -小蓝给学生们组织了一场考试,卷面总分为 分,每个学生的得分都是一个 到 的整数。 +小蓝给学生们组织了一场考试,卷面总分为100分,每个学生的得分都是一个0到100的整数。 请计算这次考试的最高分、最低分和平均分。 #### 输入格式 -输入的第一行包含一个整数 ,表示考试人数。 +输入的第一行包含一个整数n,表示考试人数。 -接下来 行,每行包含一个 至 的整数,表示一个学生的得分。 +接下来n行,每行包含一个0至100的整数,表示一个学生的得分。 #### 输出格式 输出三行。 @@ -20,6 +20,7 @@ #### 样例输入 ``` +7 80 92 56 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/solution.md" index 28aec772e..0086654bb 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\345\210\206\346\236\220/solution.md" @@ -1,13 +1,13 @@ # 成绩分析 #### 问题描述 -小蓝给学生们组织了一场考试,卷面总分为 分,每个学生的得分都是一个 到 的整数。 +小蓝给学生们组织了一场考试,卷面总分为100分,每个学生的得分都是一个0到100的整数。 请计算这次考试的最高分、最低分和平均分。 #### 输入格式 -输入的第一行包含一个整数 ,表示考试人数。 +输入的第一行包含一个整数n,表示考试人数。 -接下来 行,每行包含一个 至 的整数,表示一个学生的得分。 +接下来n行,每行包含一个0至100的整数,表示一个学生的得分。 #### 输出格式 输出三行。 @@ -21,6 +21,7 @@ #### 样例输入 ``` +7 80 92 56 @@ -39,7 +40,10 @@ ## aop ### before ```cpp +#include +#include +using namespace std; ``` ### after ```cpp @@ -48,21 +52,102 @@ ## 答案 ```cpp +int main() +{ + int n; + cin >> n; + int sum = 0; + int top = 0; + int low = 100; + + int score; + for (int i = 0; i < n; i++) + { + cin >> score; + if (score > top) + top = score; + if (score < low) + low = score; + sum += score; + } + printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n)); + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + int n; + cin >> n; + int sum = 0; + int top = 0; + int low = 100; + + int score; + for (int i = 0; i < n; i++) + { + cin >> score; + if (score > top) + top = score; + if (score < low) + low = score; + sum += score; + } + printf("%d\n%d\n%.f", top, low, (sum * 1.0 / n)); + return 0; +} ``` ### B ```cpp - +int main() +{ + int n; + cin >> n; + int sum = 0; + int top = 0; + int low = 100; + + int score; + for (int i = 0; i < n; i++) + { + cin >> score; + if (score > top) + score = top; + if (score < low) + score = low; + sum += score; + } + printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n)); + return 0; +} ``` ### C ```cpp - +int main() +{ + int n; + cin >> n; + int sum = 0; + int top = 0; + int low = 100; + + int score; + for (int i = 0; i < n; i++) + { + cin >> score; + if (score < top) + top = score; + if (score > low) + low = score; + sum += score; + } + printf("%d\n%d\n%d", top, low, (sum / n)); + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\347\273\237\350\256\241/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\347\273\237\350\256\241/solution.md" index b0ab3cb53..0425ec991 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\347\273\237\350\256\241/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\210\220\347\273\251\347\273\237\350\256\241/solution.md" @@ -20,7 +20,8 @@ yx1 ## aop ### before ```cpp - +#include +using namespace std; ``` ### after ```cpp @@ -29,21 +30,154 @@ yx1 ## 答案 ```cpp +int main() +{ + struct student + { + string xm; + int xh; + double yy; + double sx; + double cpp; + }; + student a[1000]; + int n; + double sum = 0, min = 301, max = 0; + string mins, maxs; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp; + sum = a[i].yy + a[i].sx + a[i].cpp; + if (min > sum) + { + min = sum; + mins = a[i].xm; + } + if (max < sum) + { + max = sum; + maxs = a[i].xm; + } + } + cout << maxs << endl + << mins; + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + struct student + { + string xm; + int xh; + double yy; + double sx; + double cpp; + }; + student a[1000]; + int n; + double sum = 0, min = 301, max = 0; + string mins, maxs; + cin >> n; + for (int i = 1; i < n; i++) + { + cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp; + sum = a[i].yy + a[i].sx + a[i].cpp; + if (min > sum) + { + min = sum; + mins = a[i].xm; + } + if (max < sum) + { + max = sum; + maxs = a[i].xm; + } + } + cout << maxs << endl + << mins; + return 0; +} ``` ### B ```cpp - +int main() +{ + struct student + { + string xm; + int xh; + double yy; + double sx; + double cpp; + }; + student a[1000]; + int n; + double sum = 0, min = 301, max = 0; + string mins, maxs; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp; + sum = a[i].yy + a[i].sx + a[i].cpp; + if (min > sum) + { + min = sum; + mins = a[i]->xm; + } + if (max < sum) + { + max = sum; + maxs = a[i]->xm; + } + cout << maxs << endl + << mins; + return 0; + } +} ``` ### C ```cpp - +int main() +{ + struct student + { + string xm; + int xh; + double yy; + double sx; + double cpp; + }; + student a[1000]; + int n; + double sum = 0, min = 301, max = 0; + string mins, maxs; + cin >> n; + for (int i = 0; i < n; i++) + { + cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp; + sum = a[i].yy + a[i].sx + a[i].cpp; + if (min > sum) + { + min = sum; + mins = a[i].xm; + } + if (max < sum) + { + max = sum; + maxs = a[i].xm; + } + } + cout << mins << endl + << maxs; + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\345\233\276\345\275\242/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\345\233\276\345\275\242/solution.md" index c8439cbc3..8072aab21 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\345\233\276\345\275\242/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\345\233\276\345\275\242/solution.md" @@ -63,30 +63,111 @@ ran=6 ## aop ### before ```cpp +#include +#define N 70 ``` ### after ```cpp +int main() +{ + char a[N][N]; + int i, j; + for (i = 0; i < N; i++) + for (j = 0; j < N; j++) + a[i][j] = ' '; + + + f(a, 4, 0, 0); + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + printf("%c", a[i][j]); + printf("\n"); + } + + return 0; +} ``` ## 答案 ```cpp +void f(char a[][N], int rank, int row, int col) +{ + if (rank == 1) + { + a[row][col] = '*'; + return; + } + int w = 1; + int i; + for (i = 0; i < rank - 1; i++) + w *= 2; + f(a, rank - 1, row, col + w / 2); + f(a, rank - 1, row + w / 2, col); + f(a, rank - 1, row + w / 2, col + w); +} ``` ## 选项 ### A ```cpp +void f(char a[][N], int rank, int row, int col) +{ + if (rank == 1) + { + a[row][col] = '*'; + return; + } + int w = 1; + int i; + for (i = 0; i < rank; i++) + w *= 2; + f(a, rank - 1, row, col + w / 2); + f(a, rank - 1, row + w / 2, col); + f(a, rank - 1, row + w / 2, col + w); +} ``` ### B ```cpp +void f(char a[][N], int rank, int row, int col) +{ + if (rank == 1) + { + a[row][col] = '*'; + return; + } + int w = 1; + int i; + for (i = 0; i < rank - 1; i++) + w *= 2; + f(a, rank + 1, row, col + w / 2); + f(a, rank + 1, row + w / 2, col); + f(a, rank + 1, row + w / 2, col + w); +} ``` ### C ```cpp +void f(char a[][N], int rank, int row, int col) +{ + if (rank == 1) + { + a[row][col] = '*'; + return; + } + int w = 0; + int i; + for (i = 0; i < rank - 1; i++) + w *= 2; + f(a, rank - 1, row, col + w / 2); + f(a, rank - 1, row + w / 2, col); + f(a, rank - 1, row + w / 2, col + w); +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/config.json" deleted file mode 100644 index f6416a1a5..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/config.json" +++ /dev/null @@ -1,6 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/desc.md" deleted file mode 100644 index 22177807a..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/desc.md" +++ /dev/null @@ -1,20 +0,0 @@ -给出菱形的边长,在控制台上打印出一个菱形来。 -为了便于比对空格,我们把空格用句点代替。 -当边长为8时,菱形为: -``` - * - * * - * * - * * - * * - * * - * * -* * - * * - * * - * * - * * - * * - * * - * -``` \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.cpp" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.java" deleted file mode 100644 index 8eb5a6985..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.java" +++ /dev/null @@ -1,24 +0,0 @@ - -public class Main { - - public static void main(String[] args) { - f(8); - } - - public static void f(int n) { - String s = "*"; - for (int i = 0; i < 2 * n - 3; i++) - s += "."; - s += "*"; - - String s1 = s + "\n"; - String s2 = ""; - - for (int i = 0; i < n - 1; i++) { - s = "." + s.substring(0, s.length() - 3) + "*"; // 填空 - s1 = s + "\n" + s1; - s2 += s + "\n"; - } - System.out.println(s1 + s2); - } -} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.md" deleted file mode 100644 index 28de2281c..000000000 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\223\345\215\260\350\217\261\345\275\242/solution.md" +++ /dev/null @@ -1,52 +0,0 @@ -# 打印菱形 -给出菱形的边长,在控制台上打印出一个菱形来。 -为了便于比对空格,我们把空格用句点代替。 -当边长为8时,菱形为: -``` - * - * * - * * - * * - * * - * * - * * -* * - * * - * * - * * - * * - * * - * * - * -``` - -## aop -### before -```cpp - -``` -### after -```cpp - -``` - -## 答案 -```cpp - -``` -## 选项 - -### A -```cpp - -``` - -### B -```cpp - -``` - -### C -```cpp - -``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.cpp" index 8f69d4b8d..029a3e398 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.cpp" @@ -21,7 +21,7 @@ int main() for (ll j = 1; j <= i; j++) { a[i + 1][j] += (0.5 * a[i][j]); - a[i + 1][j + 1] += (0.5 * a[i][j]); + a[i][j + 1] += (0.5 * a[i][j]); } } double minn = 1000000000, maxx = -1; diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.md" index ba2258c9b..10a8191da 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\211\277\345\216\213\350\256\241\347\256\227/solution.md" @@ -54,6 +54,14 @@ X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X ## aop ### before ```cpp +#include +#include +#include +#include +using namespace std; +typedef long long ll; +const ll maxn = 1e6 + 50; +double a[1050][1050]; ``` ### after @@ -63,21 +71,123 @@ X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X ## 答案 ```cpp - +int main() +{ + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + scanf("%lf", &a[i][j]); + } + } + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + a[i + 1][j] += (0.5 * a[i][j]); + a[i + 1][j + 1] += (0.5 * a[i][j]); + } + } + double minn = 1000000000, maxx = -1; + for (ll i = 1; i <= 30; i++) + { + maxx = max(maxx, a[30][i]); + minn = min(minn, a[30][i]); + printf("%lf\n", a[30][i]); + } + printf("%lf\n", maxx * 2086458231 / minn); +} ``` ## 选项 ### A ```cpp +int main() +{ + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + scanf("%lf", &a[i][j]); + } + } + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + a[i + 1][j] += (0.5 * a[i][j]); + a[i + 1][j + 1] += (0.5 * a[i][j]); + } + } + double minn = 1000000000, maxx = -1; + for (ll i = 1; i <= 29; i++) + { + maxx = max(maxx, a[30][i]); + minn = min(minn, a[30][i]); + printf("%lf\n", a[30][i]); + } + printf("%lf\n", maxx * 2086458231 / minn); +} ``` ### B ```cpp - +int main() +{ + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + scanf("%lf", &a[i][j]); + } + } + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + a[i + 1][j] = (0.5 * a[i][j]); + a[i + 1][j + 1] = (0.5 * a[i][j]); + } + } + double minn = 1000000000, maxx = -1; + for (ll i = 1; i <= 29; i++) + { + maxx = max(maxx, a[30][i]); + minn = min(minn, a[30][i]); + printf("%lf\n", a[30][i]); + } + printf("%lf\n", maxx * 2086458231 / minn); +} ``` ### C ```cpp +int main() +{ + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + scanf("%lf", &a[i][j]); + } + } + for (ll i = 1; i <= 29; i++) + { + for (ll j = 1; j <= i; j++) + { + a[i + 1][j] += (0.5 * a[i][j]); + a[i][j + 1] += (0.5 * a[i][j]); + } + } + double minn = 1000000000, maxx = -1; + for (ll i = 1; i <= 30; i++) + { + maxx = max(maxx, a[30][i]); + minn = min(minn, a[30][i]); + printf("%lf\n", a[30][i]); + } + printf("%lf\n", maxx * 2086458231 / minn); +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\212\275\347\255\276/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\212\275\347\255\276/solution.md" index 1971b922b..b156e70f4 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\212\275\347\255\276/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\212\275\347\255\276/solution.md" @@ -36,30 +36,96 @@ C国最多可以派出2人。 ## aop ### before ```cpp - +#include +using namespace std; +int a[10000], N, i, ans = 0; ``` ### after ```cpp +int main() +{ + + cin >> N; + for (i = 0; i < N; i++) + { + cin >> a[i]; + } + findAns(a, 0, 0); + cout << ans << endl; + return 0; +} ``` ## 答案 ```cpp +void findAns(int a[], int start, int An) +{ + if (start == N) + { + if (An == 5) + ans++; + return; + } + for (i = 0; i <= a[start]; i++) + { + findAns(a, start + 1, An + i); + } +} ``` ## 选项 ### A ```cpp +void findAns(int a[], int start, int An) +{ + if (start == N) + { + if (An == 5) + ans++; + return; + } + for (i = 0; i <= a[start]; i++) + { + findAns(a, start + 1, An); + } +} ``` ### B ```cpp +void findAns(int a[], int start, int An) +{ + if (start == N) + { + if (An == 5) + ans++; + return; + } + for (i = 0; i <= a[start]; i++) + { + findAns(a, start, An + i); + } +} ``` ### C ```cpp +void findAns(int a[], int start, int An) +{ + if (start == N) + { + if (An == 5) + ans++; + return; + } + for (i = 0; i <= a[start]; i++) + { + findAns(a, start, An + 1); + } +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\220\255\347\247\257\346\234\250/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\220\255\347\247\257\346\234\250/solution.md" index a26c15af2..8008e045f 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\220\255\347\247\257\346\234\250/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\220\255\347\247\257\346\234\250/solution.md" @@ -25,30 +25,160 @@ ## aop ### before ```cpp +#include +using namespace std; +int row = 4, col; +int seq[5][8]; +int tmp[11]; +int cnt = 0; +bool used[10]; +void change() +{ + int cur = 1; + for (int i = 1; i <= row; ++i) + { + for (int j = 1; j <= i; ++j) + { + seq[i][j] = tmp[cur++]; + } + } +} + +bool judge() +{ + for (int i = 1; i <= row - 1; ++i) + { + for (int j = 1; j <= i; ++j) + { + if (seq[i][j] > seq[i + 1][j] || seq[i][j] > seq[i + 1][j + 1]) + return false; + } + } + return true; +} +int ans = 0; ``` ### after ```cpp - +int main() +{ + memset(used, false, sizeof(used)); + dfs(1); + cout << cnt << endl; + return 0; +} ``` ## 答案 ```cpp - +void dfs(int idx) +{ + + if (idx == 11) + { + change(); + if (judge()) + { + cnt++; + return; + } + return; + } + for (int i = 0; i <= 9; ++i) + { + if (!used[i]) + { + tmp[idx] = i; + used[i] = true; + dfs(idx + 1); + used[i] = false; + } + } +} ``` ## 选项 ### A ```cpp - +void dfs(int idx) +{ + + if (idx == 11) + { + change(); + if (judge()) + { + cnt++; + return; + } + return; + } + for (int i = 0; i <= 9; ++i) + { + if (!used[i]) + { + tmp[idx] = i; + used[i] = true; + dfs(idx); + used[i] = false; + } + } +} ``` ### B ```cpp - +void dfs(int idx) +{ + + if (idx == 11) + { + change(); + if (judge()) + { + cnt++; + return; + } + return; + } + for (int i = 0; i <= 9; ++i) + { + if (!used[i]) + { + tmp[idx] = i; + used[i] = false; + dfs(idx); + used[i] = true; + } + } +} ``` ### C ```cpp - +void dfs(int idx) +{ + + if (idx == 11) + { + change(); + if (judge()) + { + cnt++; + return; + } + return; + } + for (int i = 0; i <= 9; ++i) + { + if (!used[i]) + { + tmp[idx] = i; + used[i] = false; + dfs(idx + 1); + used[i] = true; + } + } +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\254\241\346\225\260\345\267\256/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\254\241\346\225\260\345\267\256/solution.md" index a5be22e51..29a331e9b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\254\241\346\225\260\345\267\256/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\254\241\346\225\260\345\267\256/solution.md" @@ -37,7 +37,8 @@ bbccccddaaaacccc ## aop ### before ```cpp - +#include +#include ``` ### after ```cpp @@ -46,21 +47,117 @@ bbccccddaaaacccc ## 答案 ```cpp - +int main() +{ + char s[1000]; + scanf("%s", &s); + int len = strlen(s); + int helper[256] = {0}; + int max = 0, min = len; + for (int i = 0; i < len; i++) + { + helper[s[i]]++; + } + for (int i = 0; i < 256; i++) + { + if (helper[i] > max) + { + max = helper[i]; + } + if (helper[i] < min && helper[i] != 0) + { + min = helper[i]; + } + } + printf("%d\n", max - min); + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + char s[1000]; + scanf("%s", &s); + int len = strlen(s); + int helper[256] = {0}; + int max = 0, min = len; + for (int i = 0; i < len; i++) + { + helper[s[i]]++; + } + for (int i = 0; i < 256; i++) + { + if (helper[i] > max) + { + max = helper[i]; + } + if (helper[i] < min) + { + min = helper[i]; + } + } + printf("%d\n", max - min); + return 0; +} ``` ### B ```cpp - +int main() +{ + char s[1000]; + scanf("%s", &s); + int len = strlen(s); + int helper[256] = {0}; + int max = 0, min = len; + for (int i = 0; i < len; i++) + { + helper[s[i]]++; + } + for (int i = 0; i < 256; i++) + { + if (helper[i] > max) + { + max = helper[i]; + } + if (helper[i] < min && helper[i] == 0) + { + min = helper[i]; + } + } + printf("%d\n", max - min); + return 0; +} ``` ### C ```cpp - +int main() +{ + char s[1000]; + scanf("%s", &s); + int len = strlen(s); + int helper[256] = {0}; + int max = 0, min = len; + for (int i = 0; i < len; i++) + { + helper[s[i]]++; + } + for (int i = 0; i < 256; i++) + { + if (helper[i] < max) + { + max = helper[i]; + } + if (helper[i] > min) + { + min = helper[i]; + } + } + printf("%d\n", max - min); + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" index a5aeaf878..374cfde77 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" @@ -25,7 +25,17 @@ ## aop ### before ```cpp - +#include +#include +#include +using namespace std; +typedef long long ll; +const int N = 1e3 + 5; +const int mod = 100000007; +int n, s, a, b, up; +ll v; +int dp[2][N * (N + 1) / 2], now; +int ans; ``` ### after ```cpp @@ -34,21 +44,111 @@ ## 答案 ```cpp - +int main() +{ + scanf("%d%d%d%d", &n, &s, &a, &b); + dp[now][0] = 1; + for (int i = 1; i < n; ++i) + { + now = !now; + up = i * (i + 1) / 2; + for (int j = 0; j <= up; ++j) + { + dp[now][j] = dp[!now][j]; + if (j >= i) + dp[now][j] = (dp[now][j] + dp[!now][j - i]) % mod; + } + } + for (int i = 0; i <= up; ++i) + { + v = 1ll * s - 1ll * i * a + 1ll * (up - i) * b; + if (v % n == 0) + ans = (ans + dp[now][i]) % mod; + } + printf("%d\n", ans); + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + scanf("%d%d%d%d", &n, &s, &a, &b); + dp[now][0] = 1; + for (int i = 1; i < n; ++i) + { + now = !now; + up = i * (i + 1) / 2; + for (int j = 0; j <= up; ++j) + { + dp[now][j] = dp[now][j]; + if (j >= i) + dp[now][j] = (dp[now][j] + dp[!now][j - i]) % mod; + } + } + for (int i = 0; i <= up; ++i) + { + v = 1ll * s - 1ll * i * a + 1ll * (up - i) * b; + if (v % n == 0) + ans = (ans + dp[now][i]) % mod; + } + printf("%d\n", ans); + return 0; +} ``` ### B ```cpp - +int main() +{ + scanf("%d%d%d%d", &n, &s, &a, &b); + dp[now][0] = 1; + for (int i = 1; i < n; ++i) + { + up = i * (i + 1) / 2; + for (int j = 0; j <= up; ++j) + { + dp[now][j] = dp[!now][j]; + if (j >= i) + dp[now][j] = (dp[now][j] + dp[now][j - i]) % mod; + } + } + for (int i = 0; i <= up; ++i) + { + v = 1ll * s - 1ll * i * a + 1ll * (up - i) * b; + if (v % n == 0) + ans = (ans + dp[now][i]) % mod; + } + printf("%d\n", ans); + return 0; +} ``` ### C ```cpp - +int main() +{ + scanf("%d%d%d%d", &n, &s, &a, &b); + dp[now][0] = 1; + for (int i = 1; i < n; ++i) + { + up = i * (i + 1) / 2; + for (int j = 0; j <= up; ++j) + { + dp[now][j] = dp[!now][j]; + if (j >= i) + dp[now][j] = (dp[!now][j] + dp[!now][j - i]) % mod; + } + } + for (int i = 0; i <= up; ++i) + { + v = 1ll * s - 1ll * i * a + 1ll * (up - i) * b; + if (v % n == 0) + ans = (ans + dp[now][i]) % mod; + } + printf("%d\n", ans); + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\265\213\350\257\225\346\254\241\346\225\260/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\265\213\350\257\225\346\254\241\346\225\260/solution.md" index dab52dcfc..38a81a573 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\265\213\350\257\225\346\254\241\346\225\260/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\346\265\213\350\257\225\346\254\241\346\225\260/solution.md" @@ -16,30 +16,96 @@ x星球有很多高耸入云的高塔,刚好可以用来做耐摔测试。塔 ## aop ### before ```cpp - +#include +using namespace std; +int num[5][1010] = {0}; ``` ### after ```cpp - +int main() +{ + cout << dp(3, 1000) << endl; + return 0; +} ``` ## 答案 ```cpp - +int dp(int k, int n) +{ + int res = 10000; + if (n == 0) + return 0; + if (k == 1) + return n; + if (num[k][n]) + return num[k][n]; + for (int i = 1; i <= n; i++) + { + res = min(res, max(dp(k - 1, i - 1), dp(k, n - i)) + 1); + } + num[k][n] = res; + return res; +} ``` ## 选项 ### A ```cpp - +int dp(int k, int n) +{ + int res = 10000; + if (n == 0) + return 0; + if (k == 1) + return n; + if (num[k][n]) + return num[k][n]; + for (int i = 1; i <= n; i++) + { + res = max(res, min(dp(k - 1, i - 1), dp(k, n - 1)) + 1); + } + num[k][n] = res; + return res; +} ``` ### B ```cpp - +int dp(int k, int n) +{ + int res = 10000; + if (n == 0) + return 0; + if (k == 1) + return n; + if (num[k][n]) + return num[k][n]; + for (int i = 1; i <= n; i++) + { + res = min(res, max(dp(k + 1, i + 1), dp(k, n - i)) + 1); + } + num[k][n] = res; + return res; +} ``` ### C ```cpp - +int dp(int k, int n) +{ + int res = 10000; + if (n == 0) + return 0; + if (k == 1) + return n; + if (num[k][n]) + return num[k][n]; + for (int i = 1; i <= n; i++) + { + res = min(res, max(dp(k - 1, i), dp(k, n - i)) + 1); + } + num[k][n] = res; + return res; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\255\227\346\257\215/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\255\227\346\257\215/solution.md" index b711d9f7d..046323e3b 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\255\227\346\257\215/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\255\227\346\257\215/solution.md" @@ -6,7 +6,9 @@ ## aop ### before ```cpp - +#include +#include +using namespace std; ``` ### after ```cpp @@ -15,21 +17,89 @@ ## 答案 ```cpp - +int main() +{ + vector vc1; + int i; + for (i = 0; i < 2014; i++) + vc1.push_back('a' + (i % 19)); + while (vc1.size() != 1) + { + vector vc2; + cout << vc1.size() << endl; + for (i = 1; i < vc1.size(); i += 2) + vc2.push_back(vc1[i]); + vc1.assign(vc2.begin(), vc2.end()); + cout << vc1.size() << endl; + } + cout << vc1[0] << endl; + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + vector vc1; + int i; + for (i = 0; i < 2014; i++) + vc1.push_back('a' + (i % 19)); + while (vc1.size() != 1) + { + vector vc2; + cout << vc1.size() << endl; + for (i = 0; i < vc1.size(); i++) + vc2.push_back(vc1[i]); + vc1.assign(vc2.begin(), vc2.end()); + cout << vc1.size() << endl; + } + cout << vc1[0] << endl; + return 0; +} ``` ### B ```cpp - +int main() +{ + vector vc1; + int i; + for (i = 0; i < 2014; i++) + vc1.push_back('a' + (i % 19)); + while (vc1.size() != 1) + { + vector vc2; + cout << vc1.size() << endl; + for (i = 0; i < vc1.size(); i += 1) + vc2.push_back(vc1[i]); + vc1.assign(vc2.begin(), vc2.end()); + cout << vc1.size() << endl; + } + cout << vc1[0] << endl; + return 0; +} ``` ### C ```cpp - +int main() +{ + vector vc1; + int i; + for (i = 0; i < 2014; i++) + vc1.push_back('a' + (i % 19)); + while (vc1.size() != 1) + { + vector vc2; + cout << vc1.size() << endl; + for (i = 0; i < vc1.size(); i += 2) + vc2.push_back(vc1[i]); + vc1.assign(vc2.begin(), vc2.end()); + cout << vc1.size() << endl; + } + cout << vc1[0] << endl; + return 0; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\271\264\351\276\204/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\271\264\351\276\204/solution.md" index 1514f0618..55f515e2e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\271\264\351\276\204/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\347\214\234\345\271\264\351\276\204/solution.md" @@ -11,26 +11,38 @@ ``` ### after ```cpp - +#include +using namespace std; +int main() +{ + for (int i = 11; i < 35; i++) + { + int i1 = i * i * i; + int i2 = i * i1; + if ((i1 >= 1000 && i1 < 10000) && (i2 >= 100000 && i2 < 1000000)) + cout << i << " " << i1 << " " << i2 << endl; + } + return 0; +} ``` ## 答案 ```cpp - +18 ``` ## 选项 ### A ```cpp - +19 ``` ### B ```cpp - +20 ``` ### C ```cpp - +21 ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\266\205\347\272\247\350\203\266\346\260\264/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\266\205\347\272\247\350\203\266\346\260\264/solution.cpp" index 42d6a27e7..e324a5728 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\266\205\347\272\247\350\203\266\346\260\264/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\350\266\205\347\272\247\350\203\266\346\260\264/solution.cpp" @@ -1,39 +1,39 @@ -#include +#include using namespace std; - - -const int maxn=100005; - + +const int maxn = 100005; + int numv[maxn]; int v[maxn]; - - -int dfs(int idx){ - if(idx==0) - return 0; - - if(idx==1) - return v[0]*v[1]; - - int max_,a=0x3f3f3f,b=0x3f3f3f3f,c=0; - if(idx>=2) - a=(v[idx]*v[idx-1]+dfs(idx-2)+numv[idx-2]*(v[idx]+v[idx-1])); //与左边粘 - b=v[idx]*numv[idx-1]+dfs(idx-1); //与左边不粘 - c=min(a,b); + +int dfs(int idx) +{ + if (idx == 0) + return 0; + + if (idx == 1) + return v[0] * v[1]; + + int max_, a = 0x3f3f3f, b = 0x3f3f3f3f, c = 0; + if (idx >= 2) + a = (v[idx] * v[idx - 1] + dfs(idx - 2) + numv[idx - 2] * (v[idx] + v[idx - 1])); //与左边粘 + b = v[idx] * numv[idx - 1] + dfs(idx - 1); //与左边不粘 + c = min(a, b); return c; } - - -int main(){ - + +int main() +{ + int n; - scanf("%d",&n); - for(int i=0;i +using namespace std; + + +const int maxn=100005; + +int numv[maxn]; +int v[maxn]; + ``` ### after ```cpp - + +int main(){ + + int n; + scanf("%d",&n); + for(int i=0;i=2) + a=(v[idx]*v[idx-1]+dfs(idx-2)+numv[idx-2]*(v[idx]+v[idx-1])); + b=v[idx]*numv[idx-1]+dfs(idx-1); + c=min(a,b); + return c; +} ``` ## 选项 ### A ```cpp +int dfs(int idx) +{ + if (idx == 0) + return 0; + if (idx == 1) + return v[0] * v[1]; + + int max_, a = 0x3f3f3f, b = 0x3f3f3f3f, c = 0; + if (idx >= 2) + a = (v[idx] * v[idx] + dfs(idx - 2) + numv[idx - 2] * (v[idx] + v[idx - 1])); + b = v[idx] * numv[idx] + dfs(idx - 1); + c = min(a, b); + return c; +} ``` ### B ```cpp +int dfs(int idx) +{ + if (idx == 0) + return 0; + + if (idx == 1) + return v[0] * v[1]; + int max_, a = 0x3f3f3f, b = 0x3f3f3f3f, c = 0; + if (idx >= 2) + a = (v[idx - 2] * v[idx] + dfs(idx - 2) + numv[idx - 2] * (v[idx] + v[idx - 1])); + b = v[idx - 2] * numv[idx] + dfs(idx - 1); + c = min(a, b); + return c; +} ``` ### C ```cpp +int dfs(int idx) +{ + if (idx == 0) + return 0; + + if (idx == 1) + return v[0] * v[1]; + int max_, a = 0x3f3f3f, b = 0x3f3f3f3f, c = 0; + if (idx >= 2) + a = (v[idx] * v[idx] + dfs(idx - 2) + numv[idx - 2] * (v[idx] + v[idx - 1])); + b = v[idx - 1] * numv[idx] + dfs(idx - 1); + c = min(a, b); + return c; +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\231\350\257\257\347\245\250\346\215\256/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\231\350\257\257\347\245\250\346\215\256/solution.md" index 05d60e666..5f643fd1e 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\231\350\257\257\347\245\250\346\215\256/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\351\224\231\350\257\257\347\245\250\346\215\256/solution.md" @@ -52,7 +52,14 @@ ## aop ### before ```cpp - +#include +#include +#include +#include +#include +using namespace std; +int ans[10005]; +char str[100001]; ``` ### after ```cpp @@ -61,21 +68,145 @@ ## 答案 ```cpp - +int main() +{ + int n; + cin >> n; + int i, k = 0; + getchar(); + for (i = 0; i < n; i++) + { + gets(str); + char *p; + p = strtok(str, " "); + ans[k++] = atoi(p); + while (p) + { + p = strtok(NULL, " "); + if (p) + ans[k++] = atoi(p); + } + } + sort(ans, ans + k); + int ans1, ans2; + for (i = 0; i < k - 1; i++) + { + if (ans[i + 1] - ans[i] == 2) + { + ans1 = ans[i] + 1; + } + if (ans[i + 1] == ans[i]) + ans2 = ans[i]; + } + cout << ans1 << " " << ans2; +} ``` ## 选项 ### A ```cpp - +int main() +{ + int n; + cin >> n; + int i, k = 0; + getchar(); + for (i = 0; i < n; i++) + { + gets(str); + char *p; + p = strtok(str, " "); + ans[k++] = atoi(p); + while (p) + { + p = strtok(NULL, " "); + if (p) + ans[k] = atoi(p); + } + } + sort(ans, ans + k); + int ans1, ans2; + for (i = 0; i < k - 1; i++) + { + if (ans[i + 1] - ans[i] == 2) + { + ans1 = ans[i] + 1; + } + if (ans[i + 1] == ans[i]) + ans2 = ans[i]; + } + cout << ans1 << " " << ans2; +} ``` ### B ```cpp - +int main() +{ + int n; + cin >> n; + int i, k = 0; + getchar(); + for (i = 0; i < n; i++) + { + gets(str); + char *p; + p = strtok(str, " "); + ans[k++] = atoi(p); + while (p) + { + p = strtok(NULL, " "); + if (p) + ans[k++] = atoi(p); + } + } + sort(ans, ans + k); + int ans1, ans2; + for (i = 0; i < k - 1; i++) + { + if (ans[i + 1] - ans[i] == 2) + { + ans1 = ans[i + 1]; + } + if (ans[i + 1] == ans[i]) + ans2 = ans[i]; + } + cout << ans1 << " " << ans2; +} ``` ### C ```cpp - +int main() +{ + int n; + cin >> n; + int i, k = 0; + getchar(); + for (i = 0; i < n; i++) + { + gets(str); + char *p; + p = strtok(str, " "); + ans[k++] = atoi(p); + while (p) + { + p = strtok(NULL, " "); + if (p) + ans[k++] = atoi(p); + } + } + sort(ans, ans + k); + int ans1, ans2; + for (i = 0; i < k - 1; i++) + { + if (ans[i + 1] - ans[i] == 1) + { + ans1 = ans[i] + 1; + } + if (ans[i + 1] == ans[i]) + ans2 = ans[i]; + } + cout << ans1 << " " << ans2; +} ``` -- GitLab