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

update exercises

上级 fdc89a9b
......@@ -16,7 +16,10 @@
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
int bei[10];
map<long long, int> 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;
}
```
......@@ -30,30 +30,139 @@
## aop
### before
```cpp
#include <bits/stdc++.h>
#include <string>
#include <queue>
#include <set>
#include <cstring>
#include <cmath>
#include <algorithm>
#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);
}
}
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
给定正整数 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
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
}
}
# 八次求和
#### 问题描述
给定正整数 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
```
......@@ -19,30 +19,146 @@
## aop
### before
```cpp
#include <cstdio>
#include <iostream>
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;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册