From dfaba04ba7bc30d54f472d4c9b59cd3b7bd5b542 Mon Sep 17 00:00:00 2001 From: qq_44193969 Date: Mon, 15 Nov 2021 17:46:33 +0800 Subject: [PATCH] add exercises --- .../config.json" | 9 + .../desc.md" | 3 + .../solution.cpp" | 27 + .../solution.java" | 0 .../solution.json" | 6 + .../solution.md" | 46 ++ .../config.json" | 11 + .../desc.md" | 5 + .../solution.cpp" | 16 + .../solution.java" | 16 + .../solution.json" | 6 + .../solution.md" | 59 +++ .../config.json" | 9 + .../desc.md" | 23 + .../solution.cpp" | 55 ++ .../solution.java" | 0 .../solution.json" | 6 + .../solution.md" | 469 ++++++++++++++++++ .../config.json" | 9 + .../desc.md" | 7 + .../solution.cpp" | 44 ++ .../solution.java" | 0 .../solution.json" | 6 + .../solution.md" | 98 ++++ .../config.json" | 11 + .../desc.md" | 21 + .../solution.cpp" | 35 ++ .../solution.java" | 34 ++ .../solution.json" | 6 + .../solution.md" | 226 +++++++++ .../solution.md" | 66 +-- .../solution.md" | 8 +- .../solution.md" | 398 ++++++++++++++- .../solution.md" | 56 ++- .../solution.md" | 246 +++++---- 35 files changed, 1887 insertions(+), 150 deletions(-) create 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/config.json" create 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" create 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" create 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.java" create 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.json" create 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/desc.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.cpp" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.java" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.java" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.java" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/desc.md" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.cpp" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.java" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/config.json" new file mode 100644 index 00000000..4be82948 --- /dev/null +++ "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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/config.json" @@ -0,0 +1,9 @@ +{ + "node_id": "algorithm-6437a69f581f4821a5cbd4267304a905", + "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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" new file mode 100644 index 00000000..29f41714 --- /dev/null +++ "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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/desc.md" @@ -0,0 +1,3 @@ +新冠疫情由新冠病毒引起,最近在 A 国蔓延,为了尽快控制疫情,A 国准 备给大量民众进病毒核酸检测。 +然而,用于检测的试剂盒紧缺。为了解决这一困难,科学家想了一个办法:合并检测。即将从多个人(k 个)采集的标本放到同一个试剂盒中进行检测。如果结果为阴性,则说明这 k 个人都是阴性,用一个试剂盒完成了 k 个人的检测。如果结果为阳性,则说明 至少有一个人为阳性,需要将这 k 个人的样本全部重新独立检测(从理论上看, 如果检测前 k−1 个人都是阴性可以推断出第 k 个人是阳性,但是在实际操作中 不会利用此推断,而是将 k 个人独立检测),加上最开始的合并检测,一共使用 了 k + 1 个试剂盒完成了 k 个人的检测。 +A 国估计被测的民众的感染率大概是 1%,呈均匀分布。请问 k 取多少能最节省试剂盒? 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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" new file mode 100644 index 00000000..5f1e6003 --- /dev/null +++ "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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.cpp" @@ -0,0 +1,27 @@ +#include +using namespace std; +int main() +{ + int N = 1000; + int ans; + int minn = 9999999; + int sum = 0; //试剂盒的数量 + for (int k = 1; k <= 1000; k++) + { + if (N % k == 0) + { + sum = N / k + 10 * k; + } + else + { + sum = N / k + 10 * k + 1; + } + if (sum < minn) + { + minn = sum; + ans = k; + } + } + 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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.java" new file mode 100644 index 00000000..e69de29b 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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.json" new file mode 100644 index 00000000..af49dc23 --- /dev/null +++ "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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "CSDN.net", + "source": "solution.md", + "exercise_id": "c0a643a9222e49c4a0996b9e61dcd5b8" +} \ 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-\345\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" new file mode 100644 index 00000000..a9338789 --- /dev/null +++ "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\237\272\347\241\200/29.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" @@ -0,0 +1,46 @@ +# 合并检测 + +新冠疫情由新冠病毒引起,最近在 A 国蔓延,为了尽快控制疫情,A 国准 备给大量民众进病毒核酸检测。 +然而,用于检测的试剂盒紧缺。为了解决这一困难,科学家想了一个办法:合并检测。即将从多个人(k 个)采集的标本放到同一个试剂盒中进行检测。如果结果为阴性,则说明这 k 个人都是阴性,用一个试剂盒完成了 k 个人的检测。如果结果为阳性,则说明 至少有一个人为阳性,需要将这 k 个人的样本全部重新独立检测(从理论上看, 如果检测前 k−1 个人都是阴性可以推断出第 k 个人是阳性,但是在实际操作中 不会利用此推断,而是将 k 个人独立检测),加上最开始的合并检测,一共使用 了 k + 1 个试剂盒完成了 k 个人的检测。 +A 国估计被测的民众的感染率大概是 1%,呈均匀分布。请问 k 取多少能最节省试剂盒? + + +## aop + +### before + +```cpp + +``` + +### after + +```cpp + +``` + +## 答案 + +```cpp +10 +``` + +## 选项 + +### A + +```cpp +8 +``` + +### B + +```cpp +9 +``` + +### C + +```cpp +12 +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/config.json" new file mode 100644 index 00000000..b64f663a --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/config.json" @@ -0,0 +1,11 @@ +{ + "node_id": "algorithm-02d2366299904fe89ebb682ba5b794f5", + "keywords": [ + "蓝桥杯", + "不同子串" + ], + "children": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/desc.md" new file mode 100644 index 00000000..39d1f68c --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/desc.md" @@ -0,0 +1,5 @@ +#### 题目描述 +一个字符串的非空子串是指字符串中长度至少为1 的连续的一段字符组成的串。 +例如,字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab,一共7 个。 +注意在计算时,只算本质不同的串的个数。 +请问,字符串```0100110001010001```有多少个不同的非空子串? diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.cpp" new file mode 100644 index 00000000..93a367a6 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.cpp" @@ -0,0 +1,16 @@ + +#include + +using namespace std; + +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; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.java" new file mode 100644 index 00000000..554e7f48 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.java" @@ -0,0 +1,16 @@ +public class Demo2 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String str = sc.next(); + sc.close(); + Set set = new HashSet(); + for (int i = 0; i < str.length() + 1; i++) { + for (int j = i + 1; j < str.length() + 1; j++) { + set.add(str.substring(i, j)); + } + } + System.out.println(set.size()); + } + +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.json" new file mode 100644 index 00000000..091a54cf --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "CSDN.net", + "source": "solution.md", + "exercise_id": "f082ace1da0e4cc49ae265c6860b4cbc" +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\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/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" new file mode 100644 index 00000000..5c69dcf0 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/6.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" @@ -0,0 +1,59 @@ +# 不同子串 + +**题目描述** + +一个字符串的非空子串是指字符串中长度至少为1 的连续的一段字符组成的串。 +例如,字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab,一共7 个。 +注意在计算时,只算本质不同的串的个数。 +请问,字符串```0100110001010001```有多少个不同的非空子串? + +以下程序实现了这一功能,请你补全空白处的内容: + +```cpp +#include +using namespace std; + +int main() +{ + set s; + string str; + cin >> str; + for (int i = 0; i < str.size(); i++) + for (int j = i; j < str.size(); j++) + __________________ + cout << s.size(); + return 0; +} +``` + + +## aop +### before +```cpp + +``` +### after +```cpp + +``` + +## 答案 +```cpp +s.insert(str.substr(i, j - i + 1)); +``` +## 选项 + +### A +```cpp +s.insert(str.substr(i, j + i + 1)); +``` + +### B +```cpp +s.insert(str.substr(i, j - i - 1)); +``` + +### C +```cpp +s.insert(str.substr(i, j - i)); +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/config.json" new file mode 100644 index 00000000..7d810a4f --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/config.json" @@ -0,0 +1,9 @@ +{ + "node_id": "algorithm-be60c4c18cd3484eb2e20cbafee77a41", + "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/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" new file mode 100644 index 00000000..92133e42 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/desc.md" @@ -0,0 +1,23 @@ +#### 问题描述 +2020 年春节期间,有一个特殊的日期引起了大家的注意:2020年2月2日。因为如果将这个日期按“yyyymmdd” 的格式写成一个8 位数是20200202,恰好是一个回文数。我们称这样的日期是回文日期。 +有人表示20200202 是“千年一遇” 的特殊日子。对此小明很不认同,因为不到2年之后就是下一个回文日期:20211202 即2021年12月2日。 +也有人表示20200202 并不仅仅是一个回文日期,还是一个ABABBABA型的回文日期。对此小明也不认同,因为大约100 年后就能遇到下一个ABABBABA 型的回文日期:21211212 即2121 年12 月12 日。算不上“千年一遇”,顶多算“千年两遇”。 +给定一个8 位数的日期,请你计算该日期之后下一个回文日期和下一个ABABBABA型的回文日期各是哪一天。 + +#### 输入格式 +输入包含一个八位整数N,表示日期。 + +#### 输出格式 +输出两行,每行1 个八位数。第一行表示下一个回文日期,第二行表示下 +一个ABABBABA 型的回文日期。 +#### 样例输入 +``` +20200202 +``` +#### 样例输出 +``` +20211202 +21211212 +``` +#### 评测用例规模与约定 +对于所有评测用例,10000101 ≤ N ≤ 89991231,保证N 是一个合法日期的8位数表示。 \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" new file mode 100644 index 00000000..772e1de8 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.cpp" @@ -0,0 +1,55 @@ +#include +#include +using namespace std; + +int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +bool check(int year) +{ + return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; +} + +int get_day(int year, int month) +{ + if (month == 2) + return 28 + check(year); + return days[month]; +} + +int main() +{ + int n; + cin >> n; + + string ans1, ans2; + bool flag1 = false, flag2 = false; + for (int i = n / 10000; i <= 9999; i++) + { + string a = to_string(i); + string b = a; + reverse(b.begin(), b.end()); + if (a + b <= to_string(n)) + continue; + + int month = stoi(b.substr(0, 2)); + int day = stoi(b.substr(2, 2)); + if (month < 1 || month > 12) + continue; + if (day < 1 || day > get_day(i, month)) + continue; + + string s1 = a.substr(0, 2); + string s2 = a.substr(2, 2); + if (!flag1) + ans1 = a + b, flag1 = true; + if (!flag2 && s1 == s2 && s1[0] != s1[1]) + ans2 = a + b, flag2 = true; + + if (flag1 && flag2) + break; + } + + cout << ans1 << endl; + cout << ans2 << endl; + return 0; +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.java" new file mode 100644 index 00000000..e69de29b diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.json" new file mode 100644 index 00000000..1802a489 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "CSDN.net", + "source": "solution.md", + "exercise_id": "f1766cea08d14590a7f0c86494c1ec4e" +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" new file mode 100644 index 00000000..8d5f3870 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/7.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" @@ -0,0 +1,469 @@ +# 回文日期 + + +**问题描述** + +2020 年春节期间,有一个特殊的日期引起了大家的注意:2020年2月2日。因为如果将这个日期按“yyyymmdd” 的格式写成一个8 位数是20200202,恰好是一个回文数。我们称这样的日期是回文日期。 +有人表示20200202 是“千年一遇” 的特殊日子。对此小明很不认同,因为不到2年之后就是下一个回文日期:20211202 即2021年12月2日。 +也有人表示20200202 并不仅仅是一个回文日期,还是一个ABABBABA型的回文日期。对此小明也不认同,因为大约100 年后就能遇到下一个ABABBABA 型的回文日期:21211212 即2121 年12 月12 日。算不上“千年一遇”,顶多算“千年两遇”。 +给定一个8 位数的日期,请你计算该日期之后下一个回文日期和下一个ABABBABA型的回文日期各是哪一天。 + + +**输入格式** + +输入包含一个八位整数N,表示日期。 + + +**输出格式** + +输出两行,每行1 个八位数。第一行表示下一个回文日期,第二行表示下 +一个ABABBABA 型的回文日期。 + +**样例输入** + +``` +20200202 +``` + +**样例输出** + +``` +20211202 +21211212 +``` + +**评测用例规模与约定** + +对于所有评测用例,10000101 ≤ N ≤ 89991231,保证N 是一个合法日期的8位数表示。 + +以下选项错误的是? + +## aop + +### before + +```cpp + +``` + +### after + +```cpp + +``` + +## 答案 + +```cpp +#define MAX 110 +#define INF 0x3f3f3f3f +#define EXP 1e-9 +#define DEUBG 0 +#define MOD 1000000007 +typedef long long ll; + +int n, m, t, k; +int year, dd, mm; +int tbm[2][13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, + 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +int isrun(int year) +{ + if (year % 100 == 0 && year % 400 == 0) + return 1; + else if (year % 100 && year % 4 == 0) + return 1; + return 0; +} + +int tonum(string s) +{ + int r = 0; + for (int i = 0; i < s.length(); i++) + { + r = r * 10 + s[i] - '0'; + } + return r; +} + +string tostring(int year) +{ + string r = ""; + while (year) + { + r = (char)(year % 10 + '0') + r; + year /= 10; + } + return r; +} + +int checkyear(int year) +{ + int p = isrun(year); + string ys = tostring(year); + + reverse(ys.begin(), ys.end()); + int mm = tonum(ys.substr(0, 2)); + int dd = tonum(ys.substr(2, 2)); + + if (mm <= 12 && dd <= tbm[p][mm]) + return 1; + else + return 0; +} + +int checkAB(int year) +{ + int p = isrun(year); + string ys = tostring(year); + reverse(ys.begin(), ys.end()); + int mm = tonum(ys.substr(0, 2)); + int dd = tonum(ys.substr(2, 2)); + if (mm == dd && mm <= 12 && dd <= tbm[p][mm]) + return 1; + else + return 0; +} + +int check(int year, int mm, int dd) +{ + string ys = tostring(year); + reverse(ys.begin(), ys.end()); + int mt = tonum(ys.substr(0, 2)); + int dt = tonum(ys.substr(2, 2)); + if (mm == mt && dd == dt) + return 0; + else + return 1; +} + +void nxtday(int p, int &mm, int &dd) +{ + if (dd < tbm[p][mm]) + { + dd++; + } + else + { + mm++; + } +} + +int main() +{ + string s; + cin >> s; + year = tonum(s.substr(0, 4)); + + int p = isrun(year); + dd = tonum(s.substr(6, 2)); + mm = tonum(s.substr(4, 2)); + + if (check(year, mm, dd)) + year++; + else + { + nxtday(p, mm, dd); + while (m <= 12 && !check(year, mm, dd)) + { + nxtday(p, mm, dd); + } + } + + while (!checkyear(year)) + { + year++; + } + string t = tostring(year); + cout << t; + reverse(t.begin(), t.end()); + cout << t << endl; + while (!checkAB(year) || !checkyear(year)) + { + year++; + } + t = tostring(year); + cout << t; + reverse(t.begin(), t.end()); + cout << t << endl; + return 0; +} +``` + +## 选项 + +### A + +```cpp +const int inf = 0x3fffffff; +const int maxn = 100100; + +string i2s(int y, int m, int d) +{ + + string str = ""; + + str = str + (char)(y / 1000 + '0') + (char)(y / 100 % 10 + '0') + (char)(y / 10 % 10 + '0') + (char)(y % 10 + '0'); + str = str + (char)(m / 10 + '0') + (char)(m % 10 + '0'); + str = str + (char)(d / 10 + '0') + (char)(d % 10 + '0'); + + return str; +} + +bool judge_1(string str) +{ + + int len = str.length(); + int n = len / 2; + for (int i = 0; i < n; i++) + if (str[i] != str[len - i - 1]) + return false; + + return true; +} + +bool judge_2(string str) +{ + + int len = str.length(); + + set st; + for (int i = 0; i < len; i++) + st.insert(str[i]); + + if (st.size() != 2) + return false; + + if ((str[0] == str[2] && str[2] == str[5] && str[5] == str[7]) && + (str[1] == str[3] && str[3] == str[4] && str[4] == str[6])) + + return true; + + return false; +} + +bool isLeap(int y) +{ + + if (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) + return true; + + return false; +} + +int main() +{ + + int n; + int y, m, d; + cin >> n; + + y = n / 10000; + m = n / 100 % 100; + d = n % 100; + + int f1 = 0, f2 = 0; + while (true) + { + + d++; + + if (d == 32 && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)) + { + + d = 1; + m++; + } + else if (d == 31 && (m == 4 || m == 6 || m == 9 || m == 11)) + { + + d = 1; + m++; + } + else if (m == 2) + { + + if (d == 30 && isLeap(y) == true) + { + d = 1; + m++; + } + else if (d == 29 && isLeap(y) == false) + { + + d = 1; + m++; + } + } + + if (m == 13) + { + + m = 1; + y++; + } + + string str = i2s(y, m, d); + + if (judge_1(str)) + { + + if (f1 == 0) + { + + cout << str << endl; + f1 = 1; + } + + if (judge_2(str)) + { + + cout << str << endl; + f2 = 1; + } + } + + if (f1 && f2) + break; + } + + return 0; +} +``` + +### B + +```cpp +int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int data[8]; +void guizheng() +{ + int tyear, tmon; + while (data[3] * 10 + data[2] > 12 || data[3] * 10 + data[2] < 1) + { + tyear = data[0] * 1000 + data[1] * 100 + data[2] * 10 + data[3]; + tyear++; + data[7] = data[0] = tyear / 1000; + data[6] = data[1] = tyear % 1000 / 100; + data[5] = data[2] = tyear % 100 / 10; + data[4] = data[3] = tyear % 10; + } + + while (data[1] * 10 + data[0] > month[data[3] * 10 + data[2] - 1] || data[1] * 10 + data[0] < 1) + { + tmon = data[4] * 1000 + data[5] * 100 + data[6] * 10 + data[7]; + tmon++; + data[7] = data[0] = tmon / 1000; + data[6] = data[1] = tmon % 1000 / 100; + data[5] = data[2] = tmon % 100 / 10; + data[4] = data[3] = tmon % 10; + } +} +int zutoshu() +{ + int num; + num = data[0] * 10000000 + data[1] * 1000000 + data[2] * 100000 + data[3] * 10000 + data[4] * 1000 + data[5] * 100 + data[6] * 10 + data[7]; + return num; +} +int ifABAB() +{ + if (data[0] == data[2] && data[1] == data[3]) + return 0; + else + return zutoshu(); +} +int main() +{ + int n; + int tyear; + scanf("%d", &n); + n++; + data[0] = n / 10000000; + data[1] = n % 10000000 / 1000000; + data[2] = n % 1000000 / 100000; + data[3] = n % 100000 / 10000; + data[4] = n % 10000 / 1000; + data[5] = n % 1000 / 100; + data[6] = n % 100 / 10; + data[7] = n % 10; + while (data[3] < data[4] || data[2] < data[5] || data[1] < data[6] || data[0] < data[7]) + { + tyear = data[0] * 1000 + data[1] * 100 + data[2] * 10 + data[3]; + tyear++; + data[7] = data[0] = tyear / 1000; + data[6] = data[1] = tyear % 1000 / 100; + data[5] = data[2] = tyear % 100 / 10; + data[4] = data[3] = tyear % 10; + guizheng(); + } + guizheng(); + printf("%d\n", zutoshu()); + while (ifABAB()) + { + tyear = data[0] * 1000 + data[1] * 100 + data[2] * 10 + data[3]; + tyear++; + data[7] = data[0] = tyear / 1000; + data[6] = data[1] = tyear % 1000 / 100; + data[5] = data[2] = tyear % 100 / 10; + data[4] = data[3] = tyear % 10; + } + printf("%d\n", zutoshu()); + return 0; +} +``` + +### C + +```cpp +int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +bool check(int year) +{ + return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; +} + +int get_day(int year, int month) +{ + if (month == 2) + return 28 + check(year); + return days[month]; +} + +int main() +{ + int n; + cin >> n; + + string ans1, ans2; + bool flag1 = false, flag2 = false; + for (int i = n / 10000; i <= 9999; i++) + { + string a = to_string(i); + string b = a; + reverse(b.begin(), b.end()); + if (a + b <= to_string(n)) + continue; + + int month = stoi(b.substr(0, 2)); + int day = stoi(b.substr(2, 2)); + if (month < 1 || month > 12) + continue; + if (day < 1 || day > get_day(i, month)) + continue; + + string s1 = a.substr(0, 2); + string s2 = a.substr(2, 2); + if (!flag1) + ans1 = a + b, flag1 = true; + if (!flag2 && s1 == s2 && s1[0] != s1[1]) + ans2 = a + b, flag2 = true; + + if (flag1 && flag2) + break; + } + + cout << ans1 << endl; + cout << ans2 << endl; + return 0; +} +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/config.json" new file mode 100644 index 00000000..2348f750 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/config.json" @@ -0,0 +1,9 @@ +{ + "node_id": "algorithm-a055909850ea405f97caa4c8db76d24c", + "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/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" new file mode 100644 index 00000000..b5f46709 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/desc.md" @@ -0,0 +1,7 @@ +A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 +要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌。 + +请填写出所有符合要求的排列中,字典序最小的那个。 + +例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。 + diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" new file mode 100644 index 00000000..948bdca9 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.cpp" @@ -0,0 +1,44 @@ +#include +using namespace std; +int n = 0; +void swap(char *a, char *b) +{ + int m; + m = *a; + *a = *b; + *b = m; +} +void pailie(string str, int k, int m) +{ + int i; + if (k > m) + { + int a = str.find('A'); + int b = str.find_last_of('A'); + int c = str.find('2'); + int d = str.find_last_of('2'); + int e = str.find('3'); + int f = str.find_last_of('3'); + int g = str.find('4'); + int l = str.find_last_of('4'); + if (b - a == 2 && d - c == 3 && f - e == 4 && l - g == 5) + { + cout << str << endl; + } + } + else + { + for (i = k; i <= m; i++) + { + swap(&str[k], &str[i]); + pailie(str, k + 1, m); + swap(&str[k], &str[i]); + } + } +} +int main() +{ + string str = "AA223344"; + pailie(str, 0, 7); + return 0; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.java" new file mode 100644 index 00000000..e69de29b diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.json" new file mode 100644 index 00000000..88ec2204 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "CSDN.net", + "source": "solution.md", + "exercise_id": "3a714025fcd941b787743411504c0b07" +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" new file mode 100644 index 00000000..575d1917 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/8.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" @@ -0,0 +1,98 @@ +# 扑克序列 + +A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 +要求:两个A中间有1张牌,两个2之间有2张牌,两个3之间有3张牌,两个4之间有4张牌。 + +请填写出所有符合要求的排列中,字典序最小的那个。 + +例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。 + +以下程序实现了这一功能,请你补全空白处内容: + +```cpp +#include +using namespace std; +int n = 0; +void swap(char *a, char *b) +{ + int m; + m = *a; + *a = *b; + *b = m; +} +void pailie(string str, int k, int m) +{ + int i; + if (k > m) + { + int a = str.find('A'); + int b = str.find_last_of('A'); + int c = str.find('2'); + int d = str.find_last_of('2'); + int e = str.find('3'); + int f = str.find_last_of('3'); + int g = str.find('4'); + int l = str.find_last_of('4'); + if (b - a == 2 && d - c == 3 && f - e == 4 && l - g == 5) + { + cout << str << endl; + } + } + else + { + for (i = k; i <= m; i++) + { + swap(&str[k], &str[i]); + __________________ + swap(&str[k], &str[i]); + } + } +} +int main() +{ + string str = "AA223344"; + pailie(str, 0, 7); + return 0; +} +``` + + +## aop + +### before + +```cpp + +``` + +### after + +```cpp + +``` + +## 答案 + +```cpp +pailie(str, k + 1, m); +``` + +## 选项 + +### A + +```cpp +pailie(str, k, m); +``` + +### B + +```cpp +pailie(str, k - 1, m); +``` + +### C + +```cpp +pailie(str, k + 1, m + 1); +``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/config.json" new file mode 100644 index 00000000..96434f5e --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/config.json" @@ -0,0 +1,11 @@ +{ + "node_id": "algorithm-f2521444c4bb4c8a9f83545493734748", + "keywords": [ + "蓝桥杯", + "波动数列" + ], + "children": [], + "export": [ + "solution.json" + ] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/desc.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/desc.md" new file mode 100644 index 00000000..e7e7d856 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/desc.md" @@ -0,0 +1,21 @@ +#### 问题描述 +观察这个数列: +1 3 0 2 -1 1 -2 ... +这个数列中后一项总是比前一项增加2或者减少3。 +栋栋对这种数列很好奇,他想知道长度为 ```n``` 和为 ```s``` 而且后一项总是比前一项增加a或者减少b的整数数列可能有多少种呢? +#### 输入格式 +  输入的第一行包含四个整数``` n s a b```,含义如前面说述。 +#### 输出格式 +  输出一行,包含一个整数,表示满足条件的方案数。由于这个数很大,请输出方案数除以100000007的余数。 +#### 样例输入 +```4 10 2 3``` +#### 样例输出 +```2``` +#### 样例说明 +这两个数列分别是```2 4 1 3```和```7 4 1 -2```。 +#### 数据规模和约定 +对于10%的数据,1<=n<=5,0<=s<=5,1<=a,b<=5; +对于30%的数据,1<=n<=30,0<=s<=30,1<=a,b<=30; +对于50%的数据,1<=n<=50,0<=s<=50,1<=a,b<=50; +对于70%的数据,1<=n<=100,0<=s<=500,1<=a, b<=50; +对于100%的数据,1<=n<=1000,-1,000,000,000<=s<=1,000,000,000,1<=a, b<=1,000,000。 diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.cpp" new file mode 100644 index 00000000..d4dd9dff --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.cpp" @@ -0,0 +1,35 @@ +#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; +int main() +{ + scanf("%d%d%d%d", &n, &s, &a, &b); + dp[now][0] = 1; + for (int i = 1; i < n; ++i) //只有n-1个增量 + { + now = !now; + up = i * (i + 1) / 2; + for (int j = 0; j <= up; ++j) //01背包 容量 方案数 + { + 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) //s-i*a-(n*(n-1)/2-i)*b 是否被n整除 + { + 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; +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.java" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.java" new file mode 100644 index 00000000..d4ed0b2a --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.java" @@ -0,0 +1,34 @@ +import java.util.Scanner; + +public class Main { + static int n, s, a, b; + static int f[][]; + static int modnum = 100000007; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + n = sc.nextInt(); + s = sc.nextInt(); + a = sc.nextInt(); + b = sc.nextInt(); + f = new int[n][n]; + f[0][0] = 1; + System.out.println(c()); + } + + private static int c() { + if (n == 1) + return 1; + + for (int j = 1; j < n; j++) + for (int i = 0; i < n; i++) + f[i][j] = (f[g(i - j * a)][j - 1] + f[g(i + j * b)][j - 1]) % modnum; + + return f[g(s)][n - 1]; + } + + private static int g(int v) { + return ((v % n) + n) % n; + } +} diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.json" new file mode 100644 index 00000000..c5f8222f --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "CSDN.net", + "source": "solution.md", + "exercise_id": "72687b82af144180853179b4838c9592" +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\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/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" new file mode 100644 index 00000000..a7d4b141 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/12.\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" @@ -0,0 +1,226 @@ +# 波动数列 + +**问题描述** + +观察这个数列: +1 3 0 2 -1 1 -2 ... +这个数列中后一项总是比前一项增加2或者减少3。 +栋栋对这种数列很好奇,他想知道长度为 ```n``` 和为 ```s``` 而且后一项总是比前一项增加a或者减少b的整数数列可能有多少种呢? + +**输入格式** + +  输入的第一行包含四个整数``` n s a b```,含义如前面说述。 + +**输出格式** + +  输出一行,包含一个整数,表示满足条件的方案数。由于这个数很大,请输出方案数除以100000007的余数。 + +**样例输入** + +```4 10 2 3``` + +**样例输出** + +```2``` + +**样例说明** + +这两个数列分别是```2 4 1 3```和```7 4 1 -2```。 + +**数据规模和约定** + +对于10%的数据,1<=n<=5,0<=s<=5,1<=a,b<=5; +对于30%的数据,1<=n<=30,0<=s<=30,1<=a,b<=30; +对于50%的数据,1<=n<=50,0<=s<=50,1<=a,b<=50; +对于70%的数据,1<=n<=100,0<=s<=500,1<=a, b<=50; +对于100%的数据,1<=n<=1000,-1,000,000,000<=s<=1,000,000,000,1<=a, b<=1,000,000。 + +以下错误的一项是? + +## aop +### before +```cpp + +``` +### after +```cpp + +``` + +## 答案 +```cpp +long long n, s, a, b; +long long sum; +long long cnt = 0; +long long mo = 100000007; +int dfs(long long nn, long long rn) +{ + + sum += nn; + if (rn == 0) + { + + if (sum == s) + { + sum -= nn; + + cnt++; + cnt %= mo; + return 1; + } + else + { + sum -= nn; + return 0; + } + } + dfs(nn + a, rn - 1); + dfs(nn + b, rn - 1); + sum -= nn; +} +int main(void) +{ + cin >> n >> s >> a >> b; + + for (long long i = s - n * a; i < s + n * b; i++) + { + sum = 0; + dfs(i, n - 1); + } + cout << cnt << endl; + return 0; +} +``` +## 选项 + +### A +```cpp +#define MAXN 1100 +#define MOD 100000007 +using namespace std; + +int F[2][MAXN * MAXN]; +int e = 0; +long long n, s, a, b; +int cnt = 0; + +void calc(int elem) +{ + int i, j; + memset(F, 0, sizeof(F)); + F[e][0] = 1; + for (i = 1; i < n; i++) + { + e = 1 - e; + for (j = 0; j <= i * (i + 1) / 2; j++) + { + if (i > j) + F[e][j] = F[1 - e][j]; + else + F[e][j] = (F[1 - e][j] + F[1 - e][j - i]) % MOD; + } + } +} + +int main() +{ + + cin >> n >> s >> a >> b; + long long i, t; + calc(n * (n - 1) / 2); + for (i = 0; i <= n * (n - 1) / 2; i++) + { + t = s - i * a + (n * (n - 1) / 2 - i) * b; + if (t % n == 0) + cnt = (cnt + F[e][i]) % MOD; + } + printf("%d", cnt); + return 0; +} +``` + +### B +```cpp +int n, s, a, b; +int num; + +void dfn(int cur, int all, int id) +{ + if (id == n) + { + if (all == s) + { + num++; + num = num % 100000007; + return; + } + else + { + return; + } + } + dfn(cur + a, all + cur + a, id + 1); + dfn(cur - b, all + cur - b, id + 1); +} +int main() +{ + long long i, total; + cin >> n >> s >> a >> b; + total = s + n * b; + for (i = s - n * a; i <= total; i++) + { + dfn(i, i, 1); + } + cout << num; + return 0; +} +``` + +### C +```cpp +const int MAXN = 1050; +typedef long long ll; + +const int mod = 100000007; +int main() +{ + ll n, s, a, b; + + scanf("%lld%lld%lld%lld", &n, &s, &a, &b); + + int T = n * (n - 1) / 2; + int dp[2][T + 1]; + memset(dp, 0, sizeof(dp)); + + int *crt = dp[0]; + int *next = dp[1]; + crt[0] = 1; + next[0] = 1; + + for (int i = 1; i < n; i++) + { + for (int j = 0; j <= (i + 1) * i / 2; j++) + { + if (j < i) + next[j] = crt[j] % mod; + + else + next[j] = (crt[j] + crt[j - i]) % mod; + } + swap(crt, next); + } + ll ans = 0; + for (ll ta = 0; ta <= T; ta++) + { + ll num = s + (T - ta) * b - ta * a; + if (num % n == 0) + { + + ans = (ans + crt[ta]) % mod; + } + } + + cout << ans; + return 0; +} +``` diff --git "a/data_backup/3.\350\223\235\346\241\245\346\235\257/30.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" "b/data_backup/3.\350\223\235\346\241\245\346\235\257/30.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" index 20176fca..5c69dcf0 100644 --- "a/data_backup/3.\350\223\235\346\241\245\346\235\257/30.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" +++ "b/data_backup/3.\350\223\235\346\241\245\346\235\257/30.\344\270\215\345\220\214\345\255\220\344\270\262/solution.md" @@ -7,22 +7,12 @@ 注意在计算时,只算本质不同的串的个数。 请问,字符串```0100110001010001```有多少个不同的非空子串? +以下程序实现了这一功能,请你补全空白处的内容: -## aop -### before ```cpp - #include - using namespace std; -``` -### after -```cpp -``` - -## 答案 -```cpp int main() { set s; @@ -30,54 +20,40 @@ int main() 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; } ``` + + +## aop +### before +```cpp + +``` +### after +```cpp + +``` + +## 答案 +```cpp +s.insert(str.substr(i, j - i + 1)); +``` ## 选项 ### 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; -} +s.insert(str.substr(i, j + i + 1)); ``` ### 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; -} +s.insert(str.substr(i, j - i - 1)); ``` ### 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; -} +s.insert(str.substr(i, j - i)); ``` diff --git "a/data_backup/3.\350\223\235\346\241\245\346\235\257/31.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" "b/data_backup/3.\350\223\235\346\241\245\346\235\257/31.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" index ce5eee85..a9338789 100644 --- "a/data_backup/3.\350\223\235\346\241\245\346\235\257/31.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" +++ "b/data_backup/3.\350\223\235\346\241\245\346\235\257/31.\345\220\210\345\271\266\346\243\200\346\265\213/solution.md" @@ -22,7 +22,7 @@ A 国估计被测的民众的感染率大概是 1%,呈均匀分布。请问 k ## 答案 ```cpp - +10 ``` ## 选项 @@ -30,17 +30,17 @@ A 国估计被测的民众的感染率大概是 1%,呈均匀分布。请问 k ### A ```cpp - +8 ``` ### B ```cpp - +9 ``` ### C ```cpp - +12 ``` diff --git "a/data_backup/3.\350\223\235\346\241\245\346\235\257/32.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" "b/data_backup/3.\350\223\235\346\241\245\346\235\257/32.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" index cc87850f..8d5f3870 100644 --- "a/data_backup/3.\350\223\235\346\241\245\346\235\257/32.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" +++ "b/data_backup/3.\350\223\235\346\241\245\346\235\257/32.\345\233\236\346\226\207\346\227\245\346\234\237/solution.md" @@ -36,6 +36,8 @@ 对于所有评测用例,10000101 ≤ N ≤ 89991231,保证N 是一个合法日期的8位数表示。 +以下选项错误的是? + ## aop ### before @@ -53,7 +55,139 @@ ## 答案 ```cpp - +#define MAX 110 +#define INF 0x3f3f3f3f +#define EXP 1e-9 +#define DEUBG 0 +#define MOD 1000000007 +typedef long long ll; + +int n, m, t, k; +int year, dd, mm; +int tbm[2][13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, + 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +int isrun(int year) +{ + if (year % 100 == 0 && year % 400 == 0) + return 1; + else if (year % 100 && year % 4 == 0) + return 1; + return 0; +} + +int tonum(string s) +{ + int r = 0; + for (int i = 0; i < s.length(); i++) + { + r = r * 10 + s[i] - '0'; + } + return r; +} + +string tostring(int year) +{ + string r = ""; + while (year) + { + r = (char)(year % 10 + '0') + r; + year /= 10; + } + return r; +} + +int checkyear(int year) +{ + int p = isrun(year); + string ys = tostring(year); + + reverse(ys.begin(), ys.end()); + int mm = tonum(ys.substr(0, 2)); + int dd = tonum(ys.substr(2, 2)); + + if (mm <= 12 && dd <= tbm[p][mm]) + return 1; + else + return 0; +} + +int checkAB(int year) +{ + int p = isrun(year); + string ys = tostring(year); + reverse(ys.begin(), ys.end()); + int mm = tonum(ys.substr(0, 2)); + int dd = tonum(ys.substr(2, 2)); + if (mm == dd && mm <= 12 && dd <= tbm[p][mm]) + return 1; + else + return 0; +} + +int check(int year, int mm, int dd) +{ + string ys = tostring(year); + reverse(ys.begin(), ys.end()); + int mt = tonum(ys.substr(0, 2)); + int dt = tonum(ys.substr(2, 2)); + if (mm == mt && dd == dt) + return 0; + else + return 1; +} + +void nxtday(int p, int &mm, int &dd) +{ + if (dd < tbm[p][mm]) + { + dd++; + } + else + { + mm++; + } +} + +int main() +{ + string s; + cin >> s; + year = tonum(s.substr(0, 4)); + + int p = isrun(year); + dd = tonum(s.substr(6, 2)); + mm = tonum(s.substr(4, 2)); + + if (check(year, mm, dd)) + year++; + else + { + nxtday(p, mm, dd); + while (m <= 12 && !check(year, mm, dd)) + { + nxtday(p, mm, dd); + } + } + + while (!checkyear(year)) + { + year++; + } + string t = tostring(year); + cout << t; + reverse(t.begin(), t.end()); + cout << t << endl; + while (!checkAB(year) || !checkyear(year)) + { + year++; + } + t = tostring(year); + cout << t; + reverse(t.begin(), t.end()); + cout << t << endl; + return 0; +} ``` ## 选项 @@ -61,17 +195,275 @@ ### A ```cpp +const int inf = 0x3fffffff; +const int maxn = 100100; + +string i2s(int y, int m, int d) +{ + + string str = ""; + + str = str + (char)(y / 1000 + '0') + (char)(y / 100 % 10 + '0') + (char)(y / 10 % 10 + '0') + (char)(y % 10 + '0'); + str = str + (char)(m / 10 + '0') + (char)(m % 10 + '0'); + str = str + (char)(d / 10 + '0') + (char)(d % 10 + '0'); + + return str; +} + +bool judge_1(string str) +{ + + int len = str.length(); + int n = len / 2; + for (int i = 0; i < n; i++) + if (str[i] != str[len - i - 1]) + return false; + + return true; +} + +bool judge_2(string str) +{ + + int len = str.length(); + + set st; + for (int i = 0; i < len; i++) + st.insert(str[i]); + + if (st.size() != 2) + return false; + + if ((str[0] == str[2] && str[2] == str[5] && str[5] == str[7]) && + (str[1] == str[3] && str[3] == str[4] && str[4] == str[6])) + + return true; + + return false; +} + +bool isLeap(int y) +{ + + if (y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) + return true; + + return false; +} + +int main() +{ + int n; + int y, m, d; + cin >> n; + + y = n / 10000; + m = n / 100 % 100; + d = n % 100; + + int f1 = 0, f2 = 0; + while (true) + { + + d++; + + if (d == 32 && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)) + { + + d = 1; + m++; + } + else if (d == 31 && (m == 4 || m == 6 || m == 9 || m == 11)) + { + + d = 1; + m++; + } + else if (m == 2) + { + + if (d == 30 && isLeap(y) == true) + { + d = 1; + m++; + } + else if (d == 29 && isLeap(y) == false) + { + + d = 1; + m++; + } + } + + if (m == 13) + { + + m = 1; + y++; + } + + string str = i2s(y, m, d); + + if (judge_1(str)) + { + + if (f1 == 0) + { + + cout << str << endl; + f1 = 1; + } + + if (judge_2(str)) + { + + cout << str << endl; + f2 = 1; + } + } + + if (f1 && f2) + break; + } + + return 0; +} ``` ### B ```cpp - +int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +int data[8]; +void guizheng() +{ + int tyear, tmon; + while (data[3] * 10 + data[2] > 12 || data[3] * 10 + data[2] < 1) + { + tyear = data[0] * 1000 + data[1] * 100 + data[2] * 10 + data[3]; + tyear++; + data[7] = data[0] = tyear / 1000; + data[6] = data[1] = tyear % 1000 / 100; + data[5] = data[2] = tyear % 100 / 10; + data[4] = data[3] = tyear % 10; + } + + while (data[1] * 10 + data[0] > month[data[3] * 10 + data[2] - 1] || data[1] * 10 + data[0] < 1) + { + tmon = data[4] * 1000 + data[5] * 100 + data[6] * 10 + data[7]; + tmon++; + data[7] = data[0] = tmon / 1000; + data[6] = data[1] = tmon % 1000 / 100; + data[5] = data[2] = tmon % 100 / 10; + data[4] = data[3] = tmon % 10; + } +} +int zutoshu() +{ + int num; + num = data[0] * 10000000 + data[1] * 1000000 + data[2] * 100000 + data[3] * 10000 + data[4] * 1000 + data[5] * 100 + data[6] * 10 + data[7]; + return num; +} +int ifABAB() +{ + if (data[0] == data[2] && data[1] == data[3]) + return 0; + else + return zutoshu(); +} +int main() +{ + int n; + int tyear; + scanf("%d", &n); + n++; + data[0] = n / 10000000; + data[1] = n % 10000000 / 1000000; + data[2] = n % 1000000 / 100000; + data[3] = n % 100000 / 10000; + data[4] = n % 10000 / 1000; + data[5] = n % 1000 / 100; + data[6] = n % 100 / 10; + data[7] = n % 10; + while (data[3] < data[4] || data[2] < data[5] || data[1] < data[6] || data[0] < data[7]) + { + tyear = data[0] * 1000 + data[1] * 100 + data[2] * 10 + data[3]; + tyear++; + data[7] = data[0] = tyear / 1000; + data[6] = data[1] = tyear % 1000 / 100; + data[5] = data[2] = tyear % 100 / 10; + data[4] = data[3] = tyear % 10; + guizheng(); + } + guizheng(); + printf("%d\n", zutoshu()); + while (ifABAB()) + { + tyear = data[0] * 1000 + data[1] * 100 + data[2] * 10 + data[3]; + tyear++; + data[7] = data[0] = tyear / 1000; + data[6] = data[1] = tyear % 1000 / 100; + data[5] = data[2] = tyear % 100 / 10; + data[4] = data[3] = tyear % 10; + } + printf("%d\n", zutoshu()); + return 0; +} ``` ### C ```cpp - +int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + +bool check(int year) +{ + return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; +} + +int get_day(int year, int month) +{ + if (month == 2) + return 28 + check(year); + return days[month]; +} + +int main() +{ + int n; + cin >> n; + + string ans1, ans2; + bool flag1 = false, flag2 = false; + for (int i = n / 10000; i <= 9999; i++) + { + string a = to_string(i); + string b = a; + reverse(b.begin(), b.end()); + if (a + b <= to_string(n)) + continue; + + int month = stoi(b.substr(0, 2)); + int day = stoi(b.substr(2, 2)); + if (month < 1 || month > 12) + continue; + if (day < 1 || day > get_day(i, month)) + continue; + + string s1 = a.substr(0, 2); + string s2 = a.substr(2, 2); + if (!flag1) + ans1 = a + b, flag1 = true; + if (!flag2 && s1 == s2 && s1[0] != s1[1]) + ans2 = a + b, flag2 = true; + + if (flag1 && flag2) + break; + } + + cout << ans1 << endl; + cout << ans2 << endl; + return 0; +} ``` diff --git "a/data_backup/3.\350\223\235\346\241\245\346\235\257/34.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" "b/data_backup/3.\350\223\235\346\241\245\346\235\257/34.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" index 42456d01..575d1917 100644 --- "a/data_backup/3.\350\223\235\346\241\245\346\235\257/34.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" +++ "b/data_backup/3.\350\223\235\346\241\245\346\235\257/34.\346\211\221\345\205\213\345\272\217\345\210\227/solution.md" @@ -7,6 +7,54 @@ A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 例如:22AA3344 比 A2A23344 字典序小。当然,它们都不是满足要求的答案。 +以下程序实现了这一功能,请你补全空白处内容: + +```cpp +#include +using namespace std; +int n = 0; +void swap(char *a, char *b) +{ + int m; + m = *a; + *a = *b; + *b = m; +} +void pailie(string str, int k, int m) +{ + int i; + if (k > m) + { + int a = str.find('A'); + int b = str.find_last_of('A'); + int c = str.find('2'); + int d = str.find_last_of('2'); + int e = str.find('3'); + int f = str.find_last_of('3'); + int g = str.find('4'); + int l = str.find_last_of('4'); + if (b - a == 2 && d - c == 3 && f - e == 4 && l - g == 5) + { + cout << str << endl; + } + } + else + { + for (i = k; i <= m; i++) + { + swap(&str[k], &str[i]); + __________________ + swap(&str[k], &str[i]); + } + } +} +int main() +{ + string str = "AA223344"; + pailie(str, 0, 7); + return 0; +} +``` ## aop @@ -26,7 +74,7 @@ A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 ## 答案 ```cpp - +pailie(str, k + 1, m); ``` ## 选项 @@ -34,17 +82,17 @@ A A 2 2 3 3 4 4, 一共4对扑克牌。请你把它们排成一行。 ### A ```cpp - +pailie(str, k, m); ``` ### B ```cpp - +pailie(str, k - 1, m); ``` ### C ```cpp - +pailie(str, k + 1, m + 1); ``` diff --git "a/data_backup/3.\350\223\235\346\241\245\346\235\257/36.\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" "b/data_backup/3.\350\223\235\346\241\245\346\235\257/36.\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" index bf46ee85..a7d4b141 100644 --- "a/data_backup/3.\350\223\235\346\241\245\346\235\257/36.\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" +++ "b/data_backup/3.\350\223\235\346\241\245\346\235\257/36.\346\263\242\345\212\250\346\225\260\345\210\227/solution.md" @@ -35,21 +35,12 @@ 对于70%的数据,1<=n<=100,0<=s<=500,1<=a, b<=50; 对于100%的数据,1<=n<=1000,-1,000,000,000<=s<=1,000,000,000,1<=a, b<=1,000,000。 +以下错误的一项是? ## 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 @@ -58,111 +49,178 @@ int ans; ## 答案 ```cpp -int main() +long long n, s, a, b; +long long sum; +long long cnt = 0; +long long mo = 100000007; +int dfs(long long nn, long long rn) { - 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; + + sum += nn; + if (rn == 0) + { + + if (sum == s) + { + sum -= nn; + + cnt++; + cnt %= mo; + return 1; + } + else + { + sum -= nn; + return 0; + } + } + dfs(nn + a, rn - 1); + dfs(nn + b, rn - 1); + sum -= nn; +} +int main(void) +{ + cin >> n >> s >> a >> b; + + for (long long i = s - n * a; i < s + n * b; i++) + { + sum = 0; + dfs(i, n - 1); + } + cout << cnt << endl; + return 0; } ``` ## 选项 ### A ```cpp +#define MAXN 1100 +#define MOD 100000007 +using namespace std; + +int F[2][MAXN * MAXN]; +int e = 0; +long long n, s, a, b; +int cnt = 0; + +void calc(int elem) +{ + int i, j; + memset(F, 0, sizeof(F)); + F[e][0] = 1; + for (i = 1; i < n; i++) + { + e = 1 - e; + for (j = 0; j <= i * (i + 1) / 2; j++) + { + if (i > j) + F[e][j] = F[1 - e][j]; + else + F[e][j] = (F[1 - e][j] + F[1 - e][j - i]) % MOD; + } + } +} + 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; + + cin >> n >> s >> a >> b; + long long i, t; + calc(n * (n - 1) / 2); + for (i = 0; i <= n * (n - 1) / 2; i++) + { + t = s - i * a + (n * (n - 1) / 2 - i) * b; + if (t % n == 0) + cnt = (cnt + F[e][i]) % MOD; + } + printf("%d", cnt); + return 0; } ``` ### B ```cpp +int n, s, a, b; +int num; + +void dfn(int cur, int all, int id) +{ + if (id == n) + { + if (all == s) + { + num++; + num = num % 100000007; + return; + } + else + { + return; + } + } + dfn(cur + a, all + cur + a, id + 1); + dfn(cur - b, all + cur - b, id + 1); +} 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; + long long i, total; + cin >> n >> s >> a >> b; + total = s + n * b; + for (i = s - n * a; i <= total; i++) + { + dfn(i, i, 1); + } + cout << num; + return 0; } ``` ### C ```cpp +const int MAXN = 1050; +typedef long long ll; + +const int mod = 100000007; 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; + ll n, s, a, b; + + scanf("%lld%lld%lld%lld", &n, &s, &a, &b); + + int T = n * (n - 1) / 2; + int dp[2][T + 1]; + memset(dp, 0, sizeof(dp)); + + int *crt = dp[0]; + int *next = dp[1]; + crt[0] = 1; + next[0] = 1; + + for (int i = 1; i < n; i++) + { + for (int j = 0; j <= (i + 1) * i / 2; j++) + { + if (j < i) + next[j] = crt[j] % mod; + + else + next[j] = (crt[j] + crt[j - i]) % mod; + } + swap(crt, next); + } + ll ans = 0; + for (ll ta = 0; ta <= T; ta++) + { + ll num = s + (T - ta) * b - ta * a; + if (num % n == 0) + { + + ans = (ans + crt[ta]) % mod; + } + } + + cout << ans; + return 0; } ``` -- GitLab