From 88724d3b71172d67aaf8087d8787de80ebe71d54 Mon Sep 17 00:00:00 2001 From: zhangzc Date: Fri, 29 Oct 2021 13:51:08 +0800 Subject: [PATCH] update exercises --- .../solution.cpp" | 2 +- .../solution.cpp" | 26 ++-- .../solution.md" | 112 ++++++++++++++++- .../solution.md" | 117 ++++++++++++++++- .../solution.md" | 119 +++++++++++++++++- 5 files changed, 355 insertions(+), 21 deletions(-) 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\272\345\206\240\346\246\202\347\216\207/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\244\272\345\206\240\346\246\202\347\216\207/solution.cpp" index 32c05c804..c0290c1f5 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\272\345\206\240\346\246\202\347\216\207/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\244\272\345\206\240\346\246\202\347\216\207/solution.cpp" @@ -20,7 +20,7 @@ int main() { if (j != i && k != i && j != k) { - sum += rate[0][i] * rate[j][k]; + sum += rate[0][i] * rate[j][k] * rate[0][j]; } } } 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\226\271\346\240\274\345\210\206\345\211\262/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\226\271\346\240\274\345\210\206\345\211\262/solution.cpp" index 9e4ec15c1..b33378cff 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\226\271\346\240\274\345\210\206\345\211\262/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\226\271\346\240\274\345\210\206\345\211\262/solution.cpp" @@ -2,37 +2,37 @@ using namespace std; int ans; -int dire[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; //代表4个方向,上下左右 -int vis[7][7]; //哪些点已被访问过 +int dire[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; +int vis[7][7]; void dfs(int x, int y) { if (x == 0 || y == 0 || x == 6 || y == 6) - { //终止出口条件,当走到边缘的时候,符合题意 + { ans++; return; } - //当前的点标注为已访问的点 + vis[x][y] = 1; - //对称的点也标注为已访问的点 + vis[6 - x][6 - y] = 1; for (int k = 0; k < 4; k++) { - int nx = x + dire[k][0]; //横坐标的增量 - int ny = y + dire[k][1]; //纵坐标的增量 - //新坐标 + int nx = x + dire[k][0]; + int ny = y + dire[k][1]; + if (nx < 0 || nx > 6 || ny < 0 || ny > 6) - continue; //越界,不符合 + continue; if (!vis[nx][ny]) - { //若新的点未被访问过 - dfs(nx, ny); //深搜 + { + dfs(nx, ny); } } vis[x][y] = 0; - vis[6 - x][6 - y] = 0; //对称 + vis[6 - x][6 - y] = 0; } int main() { - dfs(3, 3); //初始点 + dfs(3, 3); cout << ans / 4 << 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/\346\226\271\346\240\274\345\210\206\345\211\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/\346\226\271\346\240\274\345\210\206\345\211\262/solution.md" index 6852cca31..510dca4f1 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\226\271\346\240\274\345\210\206\345\211\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/\346\226\271\346\240\274\345\210\206\345\211\262/solution.md" @@ -15,30 +15,140 @@ ## aop ### before ```cpp +#include +using namespace std; +int ans; +int dire[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; +int vis[7][7]; ``` ### after ```cpp - +int main() +{ + dfs(3, 3); + cout << ans / 4 << endl; + return 0; +} ``` ## 答案 ```cpp +void dfs(int x, int y) +{ + if (x == 0 || y == 0 || x == 6 || y == 6) + { + ans++; + return; + } + + vis[x][y] = 1; + + vis[6 - x][6 - y] = 1; + for (int k = 0; k < 4; k++) + { + int nx = x + dire[k][0]; + int ny = y + dire[k][1]; + if (nx < 0 || nx > 6 || ny < 0 || ny > 6) + continue; + if (!vis[nx][ny]) + { + dfs(nx, ny); + } + } + vis[x][y] = 0; + vis[6 - x][6 - y] = 0; +} ``` ## 选项 ### A ```cpp +void dfs(int x, int y) +{ + if (x == 0 || y == 0 || x == 6 || y == 6) + { + ans++; + return; + } + + vis[x][y] = 1; + + vis[6 - x][6 - y] = 1; + for (int k = 0; k < 4; k++) + { + int nx = x + dire[k][0]; + int ny = y + dire[k][1]; + if (nx < 0 || nx > 6 || ny < 0 || ny > 6) + continue; + if (!vis[nx][ny]) + { + dfs(nx - 1, ny - 1); + } + } + vis[x][y] = 0; + vis[6 - x][6 - y] = 0; +} ``` ### B ```cpp +void dfs(int x, int y) +{ + if (x == 0 || y == 0 || x == 6 || y == 6) + { + ans++; + return; + } + vis[x][y] = 1; + + vis[6 - x][6 - y] = 1; + for (int k = 0; k < 4; k++) + { + int nx = x + dire[k][0]; + int ny = y + dire[k][1]; + + if (nx < 0 || nx > 6 || ny < 0 || ny > 6) + continue; + if (!vis[nx][ny]) + { + dfs(nx + 1, ny + 1); + } + } + vis[x][y] = 0; + vis[6 - x][6 - y] = 0; +} ``` ### C ```cpp +void dfs(int x, int y) +{ + if (x == 0 || y == 0 || x == 6 || y == 6) + { + ans++; + return; + } + + vis[x][y] = 1; + + vis[6 - x][6 - y] = 1; + for (int k = 0; k < 4; k++) + { + int nx = x + dire[k][0]; + int ny = y + dire[k][1]; + if (nx < 0 || nx > 6 || ny < 0 || ny > 6) + continue; + if (!vis[nx][ny]) + { + dfs(nx, ny + 1); + } + } + vis[x][y] = 0; + vis[6 - x][6 - y] = 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\226\271\347\250\213\346\225\264\346\225\260\350\247\243/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\226\271\347\250\213\346\225\264\346\225\260\350\247\243/solution.md" index 829f727a8..7b035c738 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\226\271\347\250\213\346\225\264\346\225\260\350\247\243/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\226\271\347\250\213\346\225\264\346\225\260\350\247\243/solution.md" @@ -25,7 +25,9 @@ No Solution ## aop ### before ```cpp - +#include +#include +using namespace std; ``` ### after ```cpp @@ -34,21 +36,134 @@ No Solution ## 答案 ```cpp +int main() +{ + int n; + bool flag = false; + while (cin >> n) + { + flag = false; + for (int i = 1; i <= sqrt(n); i++) + { + for (int j = i; j <= sqrt(n); j++) + { + for (int k = j; k <= sqrt(n); k++) + { + if (i * i + j * j + k * k == n) + { + cout << i << ' ' << j << ' ' << k << endl; + flag = true; + } + else if (i * i + j * j + k * k > n) + break; + } + } + } + if (!flag) + cout << "No Solution" << endl; + } + + return 0; +} ``` ## 选项 ### A ```cpp +int main() +{ + int n; + bool flag = false; + while (cin >> n) + { + flag = false; + for (int i = 1; i <= n; i++) + { + for (int j = i; j <= n; j++) + { + for (int k = j; k <= n; k++) + { + if (i * i + j * j + k * k == n) + { + cout << i << ' ' << j << ' ' << k << endl; + flag = true; + } + else if (i * i + j * j + k * k > n) + break; + } + } + } + if (!flag) + cout << "No Solution" << endl; + } + return 0; +} ``` ### B ```cpp +int main() +{ + int n; + bool flag = false; + while (cin >> n) + { + flag = false; + for (int i = 1; i < sqrt(n); i++) + { + for (int j = 1; j < sqrt(n); j++) + { + for (int k = 1; k < sqrt(n); k++) + { + if (i * i + j * j + k * k == n) + { + cout << i << ' ' << j << ' ' << k << endl; + flag = true; + } + else if (i * i + j * j + k * k > n) + break; + } + } + } + if (!flag) + cout << "No Solution" << endl; + } + return 0; +} ``` ### C ```cpp +int main() +{ + int n; + bool flag = false; + while (cin >> n) + { + flag = false; + for (int i = 1; i <= sqrt(n); i++) + { + for (int j = 1; j <= sqrt(n); j++) + { + for (int k = j; k <= sqrt(n); k++) + { + if (i * i + j * j + k * k == n) + { + cout << i << ' ' << j << ' ' << k << endl; + flag = true; + } + else if (i * i + j * j + k * k > n) + break; + } + } + } + if (!flag) + cout << "No Solution" << 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\277\273\347\241\254\345\270\201/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\277\273\347\241\254\345\270\201/solution.md" index be116b6f0..c424fc2c9 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\277\273\347\241\254\345\270\201/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\277\273\347\241\254\345\270\201/solution.md" @@ -40,7 +40,8 @@ o****o**** ## aop ### before ```cpp - +#include +using namespace std; ``` ### after ```cpp @@ -49,21 +50,129 @@ o****o**** ## 答案 ```cpp - +int main() +{ + string a, b; + cin >> a >> b; + int a1 = a.size(), b1 = b.size(), ans = 0; + for (int i = 0; i < a1; i++) + { + if (a[i] == b[i]) + { + continue; + } + else + { + ans++; + a[i] = b[i]; + if (a[i + 1] == '*') + { + a[i + 1] = 'o'; + } + else + { + a[i + 1] = '*'; + } + } + } + cout << ans << endl; + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + string a, b; + cin >> a >> b; + int a1 = a.size(), b1 = b.size(), ans = 0; + for (int i = 0; i < a1; i++) + { + if (a[i] == b[i]) + { + continue; + } + else + { + ans++; + a[i] = b[i]; + if (a[i + 1] == '*') + { + a[i] = 'o'; + } + else + { + a[i] = '*'; + } + } + } + cout << ans << endl; + return 0; +} ``` ### B ```cpp - +int main() +{ + string a, b; + cin >> a >> b; + int a1 = a.size(), b1 = b.size(), ans = 0; + for (int i = 0; i < a1; i++) + { + if (a[i] == b[i]) + { + continue; + } + else + { + ans++; + a[i] = b[i]; + if (a[i] == '*') + { + a[i + 1] = 'o'; + } + else + { + a[i + 1] = '*'; + } + } + } + cout << ans << endl; + return 0; +} ``` ### C ```cpp - +int main() +{ + string a, b; + cin >> a >> b; + int a1 = a.size(), b1 = b.size(), ans = 0; + for (int i = 0; i < a1; i++) + { + if (a[i] == b[i]) + { + continue; + } + else + { + ans++; + a[i] = b[i]; + if (a[i] == '*') + { + a[i + 1] = '*'; + } + else + { + a[i + 1] = 'o'; + } + } + } + cout << ans << endl; + return 0; +} ``` -- GitLab