From 7ddf3532335b0d16724f79e8082bb62b41a05f31 Mon Sep 17 00:00:00 2001 From: zhangzc Date: Thu, 28 Oct 2021 11:26:29 +0800 Subject: [PATCH] update exercises --- .../solution.md" | 194 +++++++++++++++++- .../solution.md" | 121 ++++++++++- .../config.json" | 6 - .../desc.md" | 26 --- .../solution.cpp" | 0 .../solution.java" | 16 -- .../solution.md" | 58 ------ .../solution.md" | 128 +++++++++++- 8 files changed, 430 insertions(+), 119 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/\345\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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/9\346\225\260\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/9\346\225\260\347\256\227\345\274\217/solution.md" index e4ee15db7..69dd63162 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/9\346\225\260\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/9\346\225\260\347\256\227\345\274\217/solution.md" @@ -16,7 +16,10 @@ ## aop ### before ```cpp - +#include +using namespace std; +int bei[10]; +map mp; ``` ### after ```cpp @@ -25,21 +28,210 @@ ## 答案 ```cpp +int main() +{ + int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int res = 0; + do + { + for (int i = 1; i < 9; i++) + { + memset(bei, 0, sizeof(bei)); + long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0; + for (int j = 0; j <= i; j++) + { + left = left * 10 + a[j]; + } + x = left; + x = x * 10; + for (int k = i + 1; k < 9; k++) + { + right = right * 10 + a[k]; + x = x * 10 + a[k]; + } + y = right; + y = y * 10; + for (int j = 0; j <= i; j++) + y = y * 10 + a[j]; + ans = left * right; + long long int ff = ans; + while (ans > 0) + { + int x = ans % 10; + ans = ans / 10; + if (bei[x] == 0 && x != 0) + { + bei[x] = 1; + t++; + } + } + if (t == 9 && mp.count(x) == 0 && mp.count(y) == 0) + { + res++; + mp[x] = 1; + mp[y] = 1; + } + } + } while (next_permutation(a, a + 9)); + cout << res << endl; + return 0; +} ``` ## 选项 ### A ```cpp +int main() +{ + int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int res = 0; + while (next_permutation(a, a + 9)) + { + for (int i = 1; i < 9; i++) + { + memset(bei, 0, sizeof(bei)); + long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0; + for (int j = 0; j <= i; j++) + { + left = left * 10 + a[j]; + } + x = left; + x = x * 10; + for (int k = i + 1; k < 9; k++) + { + right = right * 10 + a[k]; + } + y = right; + y = y * 10; + for (int j = 0; j <= i; j++) + y = y * 10 + a[j]; + ans = left * right; + long long int ff = ans; + while (ans >= 0) + { + int x = ans % 10; + ans = ans / 10; + if (bei[x] == 0 && x != 0) + { + bei[x] = 1; + t++; + } + } + if (mp.count(x) == 0 && mp.count(y) == 0) + { + res++; + mp[x] = 1; + mp[y] = 1; + } + } + }; + cout << res << endl; + return 0; +} ``` ### B ```cpp +int main() +{ + int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int res = 0; + do + { + for (int i = 1; i < 9; i++) + { + memset(bei, 0, sizeof(bei)); + long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0; + for (int j = 0; j <= i; j++) + { + left = left * 10 + a[j]; + } + x = left; + x = x * 10; + for (int k = i + 1; k < 9; k++) + { + right = right * 10 + a[k]; + x = x * 10 + a[k]; + } + y = right; + y = y * 10; + for (int j = 0; j <= i; j++) + y = y * 10 + a[j]; + long long int ff = ans; + while (ans > 0) + { + int x = ans % 10; + ans = ans / 10; + if (bei[x] == 0 && x != 0) + { + bei[x] = 1; + t++; + } + } + if (t == 9 && mp.count(x) == 0 && mp.count(y) == 0) + { + res++; + mp[x] = 1; + mp[y] = 1; + } + } + } while (next_permutation(a, a + 9)); + cout << res << endl; + return 0; +} ``` ### C ```cpp +int main() +{ + int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int res = 0; + while (next_permutation(a, a + 9)) + { + for (int i = 1; i < 9; i++) + { + memset(bei, 0, sizeof(bei)); + long long int ans, left = 0, right = 0, t = 0, x = 0, y = 0; + for (int j = 0; j <= i; j++) + { + left = left * 10 + a[j]; + } + x = left; + x = x * 10; + for (int k = i + 1; k < 9; k++) + { + right = right * 10 + a[k]; + } + y = right; + y = y * 10; + for (int j = 0; j <= i; j++) + y = y * 10 + a[j]; + ans = left * right; + long long int ff = ans; + while (ans > 0) + { + int x = ans % 10; + ans = ans / 10; + if (bei[x] == 0 && x != 0) + { + bei[x] = 1; + t++; + } + } + if (t == 9 && mp.count(x) == 0 && mp.count(y) == 0) + { + res++; + mp[x] = 1; + mp[y] = 1; + } + } + }; + cout << res << 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/\345\200\215\346\225\260\351\227\256\351\242\230/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\200\215\346\225\260\351\227\256\351\242\230/solution.md" index 47915b6ed..8532da82c 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\200\215\346\225\260\351\227\256\351\242\230/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\200\215\346\225\260\351\227\256\351\242\230/solution.md" @@ -30,30 +30,139 @@ ## aop ### before ```cpp - +#include +#include +#include +#include +#include +#include +#include +#define MAX 1000000000 +using namespace std; +int n, k, a[100010]; +int b[4]; +int flag = 0; ``` ### after ```cpp - +int main() +{ + cin >> n >> k; + a[0] = MAX; + for (int i = 1; i <= n; i++) + cin >> a[i]; + sort(a + 1, a + n + 1); + reverse(a + 1, a + n + 1); + dfs(a, n, 1); + return 0; +} ``` ## 答案 ```cpp - +void dfs(int a[], int n, int s) +{ + if (flag == 1) + return; + if (s == 4) + { + int sum = b[1] + b[2] + b[3]; + if (sum % k == 0) + { + flag = 1; + cout << sum << endl; + } + return; + } + for (int i = 1; i <= n; i++) + { + if (a[i] < a[s - 1]) + { + b[s] = a[i]; + dfs(a, n, s + 1); + } + } +} ``` ## 选项 ### A ```cpp - +void dfs(int a[], int n, int s) +{ + if (flag == 1) + return; + if (s == 4) + { + int sum = b[1] + b[2] + b[3]; + if (sum % k == 0) + { + flag = 1; + cout << sum << endl; + } + return; + } + for (int i = 1; i <= n; i++) + { + if (a[i] < a[s - 1]) + { + b[s] = a[i]; + dfs(a, n, s); + } + } +} ``` ### B ```cpp - +void dfs(int a[], int n, int s) +{ + if (flag == 1) + return; + if (s == 4) + { + int sum = b[1] + b[2] + b[3]; + if (sum % k == 0) + { + flag = 1; + cout << sum << endl; + } + return; + } + for (int i = 1; i <= n; i++) + { + if (a[i] < a[s + 1]) + { + b[s] = a[i]; + dfs(a, n, s + 1); + } + } +} ``` ### C ```cpp - +void dfs(int a[], int n, int s) +{ + if (flag == 1) + return; + if (s == 4) + { + int sum = b[1] + b[2] + b[3]; + if (sum % k == 0) + { + flag = 1; + cout << sum << endl; + } + return; + } + for (int i = 1; i <= n; i++) + { + if (a[i] < a[s + 1]) + { + b[s] = a[i]; + dfs(a, n, s); + } + } +} ``` 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\205\253\346\254\241\346\261\202\345\222\214/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\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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\205\253\346\254\241\346\261\202\345\222\214/desc.md" deleted file mode 100644 index b446c87d9..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/\345\205\253\346\254\241\346\261\202\345\222\214/desc.md" +++ /dev/null @@ -1,26 +0,0 @@ -#### 问题描述 -给定正整数 n, 求 1^8 + 2^8 +···+ n^8 mod 123456789 。其中 mod 表示取余。 -#### 输入格式 -输入的第一行包含一个整数 n。 -#### 输出格式 -输出一行,包含一个整数,表示答案。 -#### 样例输入 -``` -2 -``` -#### 样例输出 -``` -257 -``` -#### 样例输入 -``` -987654 -``` -#### 样例输出 -``` -43636805 -``` -#### 评测用例规模与约定 -对于 20% 的评测用例,1≤n≤20。 -对于 60% 的评测用例,1≤n≤1000。 -对于所有评测用例,1≤n≤1000000。 \ 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\205\253\346\254\241\346\261\202\345\222\214/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\205\253\346\254\241\346\261\202\345\222\214/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/\345\205\253\346\254\241\346\261\202\345\222\214/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\205\253\346\254\241\346\261\202\345\222\214/solution.java" deleted file mode 100644 index 76d920e29..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/\345\205\253\346\254\241\346\261\202\345\222\214/solution.java" +++ /dev/null @@ -1,16 +0,0 @@ -import java.util.Scanner; - -public class Main { - public static void main(String[] args) { - int mod=123456789; - Scanner s = new Scanner(System.in); - int n=s.nextInt();long result=0; - for(long i=1;i<=n;i++){//遍历1~n - long temp=1; - for(int j=1;j<=4;j++){//对每一个 i 进行八次乘方,四次循环,每次循环里面计算一次平方 - temp =(temp*((i*i) %mod))%mod; //计算平方并取模,防止溢出 } - result=(result+temp)%mod;//把每一次 i 循环得到的八次方结果汇总到变量 result 中。 - } - System.out.println(result);//打印输出 resualt - } -} 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\205\253\346\254\241\346\261\202\345\222\214/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\205\253\346\254\241\346\261\202\345\222\214/solution.md" deleted file mode 100644 index d44244b3f..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/\345\205\253\346\254\241\346\261\202\345\222\214/solution.md" +++ /dev/null @@ -1,58 +0,0 @@ -# 八次求和 -#### 问题描述 -给定正整数 n, 求 1^8 + 2^8 +···+ n^8 mod 123456789 。其中 mod 表示取余。 -#### 输入格式 -输入的第一行包含一个整数 n。 -#### 输出格式 -输出一行,包含一个整数,表示答案。 -#### 样例输入 -``` -2 -``` -#### 样例输出 -``` -257 -``` -#### 样例输入 -``` -987654 -``` -#### 样例输出 -``` -43636805 -``` -#### 评测用例规模与约定 -对于 20% 的评测用例,1≤n≤20。 -对于 60% 的评测用例,1≤n≤1000。 -对于所有评测用例,1≤n≤1000000。 - -## 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\257\224\351\205\222\351\207\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/\346\257\224\351\205\222\351\207\217/solution.md" index 66d4443eb..ddeb67154 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\257\224\351\205\222\351\207\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/\346\257\224\351\205\222\351\207\217/solution.md" @@ -19,30 +19,146 @@ ## aop ### before ```cpp - +#include +#include +using namespace std; +int d, a1[4]; ``` ### after ```cpp - +int main() +{ + for (int sum = 20; sum >= 1; sum--) + { + for (int a = 1; a <= 20; a++) + { + for (int b = 1; b <= 20; b++) + { + for (int c = 1; c <= 20; c++) + { + a1[0] = sum, a1[1] = a, a1[2] = b, a1[3] = c; + if (getS(a1) == a1[0] && a > b && b > c && sum > a) + { + printf("%d, %d, %d, %d, 0\n", sum, a, b, c); + } + } + } + } + } + return 0; +} ``` ## 答案 ```cpp - +int d1(int *a1) +{ + int sum = a1[0]; + for (int i = 1; i < 4; i++) + { + if (sum % a1[i] != 0) + return i; + } + return 0; +} +int getS(int *a1) +{ + int sum = 0, ss = 1; + while (d1(a1) != 0) + { + int index = d1(a1); + a1[0] = a1[0] * a1[index]; + ss = a1[index]; + } + for (int i = 1; i < 4; i++) + { + sum += (a1[0] / a1[i]); + } + return sum + ss; +} ``` ## 选项 ### A ```cpp - +int d1(int *a1) +{ + int sum = a1[0]; + for (int i = 1; i < 4; i++) + { + if (sum % a1[i] != 0) + return i; + } + return 0; +} +int getS(int *a1) +{ + int sum = 0, ss = 1; + while (d1(a1) != 0) + { + int index = d1(a1); + a1[0] = a1[0] * a1[index]; + ss = a1[index]; + } + for (int i = 1; i <= 4; i++) + { + sum += (a1[0] / a1[i]); + } + return sum + ss; +} ``` ### B ```cpp - +int d1(int *a1) +{ + int sum = a1[0]; + for (int i = 1; i <= 4; i++) + { + if (sum % a1[i] != 0) + return i; + } + return 0; +} +int getS(int *a1) +{ + int sum = 0, ss = 1; + while (d1(a1) != 0) + { + int index = d1(a1); + a1[0] = a1[0] * a1[index]; + ss = a1[index]; + } + for (int i = 1; i <= 4; i++) + { + sum += (a1[0] / a1[i]); + } + return sum + ss; +} ``` ### C ```cpp - +int d1(int *a1) +{ + int sum = a1[0]; + for (int i = 1; i < 4; i++) + { + if (sum % a1[i] != 0) + return i; + } + return 0; +} +int getS(int *a1) +{ + int sum = 0, ss = 1; + while (d1(a1) != 0) + { + int index = d1(a1); + a1[0] = a1[0] * a1[index]; + ss = a1[index]; + sum += ss; + } + return sum; +} ``` -- GitLab