提交 88724d3b 编写于 作者: 每日一练社区's avatar 每日一练社区

update exercises

上级 2eda9185
......@@ -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];
}
}
}
......
......@@ -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;
}
......@@ -15,30 +15,140 @@
## aop
### before
```cpp
#include <iostream>
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;
}
```
......@@ -25,7 +25,9 @@ No Solution
## aop
### before
```cpp
#include <iostream>
#include <cmath>
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;
}
```
......@@ -40,7 +40,8 @@ o****o****
## aop
### before
```cpp
#include <bits/stdc++.h>
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;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册