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

update dir sstructure

上级 1db7b816
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"9数算式"
],
"children": [],
"export": [
"solution.json"
],
"title": "9数算式"
}
\ No newline at end of file
观察如下的算式:
```
9213 x 85674 = 789314562
```
左边的乘数和被乘数正好用到了1~9的所有数字,每个1次。
而乘积恰好也是用到了1~9的所有数字,并且每个1次。
请你借助计算机的强大计算能力,找出满足如上要求的9数算式一共有多少个?
注意:
1. 总数目包含题目给出的那个示例。
2. 乘数和被乘数交换后作为同一方案来看待。
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int bei[10]; //备用
map<long long, int> mp;
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;
}
import java.util.*;
public class Main {
static int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
static int ans;
public static void main(String[] args) {
f(0);
System.out.println(ans / 2);
}
// 全排列
private static void f(int k) {
// 全排列终点
if (k == a.length) {
// 处理该种排列下所有的乘法可能
for (int i = 1; i < a.length; i++) {
int x1 = a2i(0, i);
int x2 = a2i(i, a.length);
// 如果乘积也包含了九个数字,ans++
if (check(x1 * x2)) {
ans++; // 这里没有考虑x1和x2交换顺序的情况,所以最后输出时要除以2
}
}
}
// 全排列
for (int i = k; i < a.length; i++) {
int t = a[i];
a[i] = a[k];
a[k] = t;
f(k + 1);
t = a[i];
a[i] = a[k];
a[k] = t;
}
}
// 判断x是否是一个包含九个数字的数
private static boolean check(int x) {
String s = x + "";
if (s.length() != 9 || s.indexOf('0') > -1) {
return false;
}
Set<Character> set = new HashSet<Character>();
for (int i = 0; i < s.length(); i++) {
set.add(s.charAt(i));
}
if (set.size() == 9) {
return true;
}
return false;
}
// 将a数组[begin,end)转换为整数
private static int a2i(int begin, int end) {
int res = a[begin];
for (int i = begin + 1; i < end; i++) {
res *= 10;
res += a[i];
}
return res;
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "16037b2bb49347f5b43f06ab1e23245a"
}
\ No newline at end of file
# 9数算式
观察如下的算式:
```
9213 x 85674 = 789314562
```
左边的乘数和被乘数正好用到了1~9的所有数字,每个1次。
而乘积恰好也是用到了1~9的所有数字,并且每个1次。
请你借助计算机的强大计算能力,找出满足如上要求的9数算式一共有多少个?
注意:
1. 总数目包含题目给出的那个示例。
2. 乘数和被乘数交换后作为同一方案来看待。
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
int bei[10];
map<long long, int> mp;
```
### after
```cpp
```
## 答案
```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;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"乘积尾零"
],
"children": [],
"export": [
"solution.json"
],
"title": "乘积尾零"
}
\ No newline at end of file
如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零?
```
5650 4542 3554 473 946 4114 3871 9073 90 4329
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899
1486 5722 3135 1170 4014 5510 5120 729 2880 9019
2049 698 4582 4346 4427 646 9742 7340 1230 7683
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649
6701 6645 1671 5978 2704 9926 295 3125 3878 6785
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074
689 5510 8243 6114 337 4096 8199 7313 3685 211
```
\ No newline at end of file
#include <iostream>
using namespace std;
int main()
{
int count2 = 0, count5 = 0;
int num;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
{
count5++;
num += 5;
}
while (num % 2 == 0)
{
count2++;
num += 2;
}
}
int ans = count2 < count5 ? count2 : count5;
cout << ans;
return 0;
}
import java.math.BigInteger;//输入的时候,记住要一行输所有的100个数字,
//并且每个数字之间要空一格,只能空一格,这样才能计算出答案。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String s;
BigInteger a, b;
Scanner cin = new Scanner(System.in);
s = cin.nextLine();
String[] num = s.split(" ");
BigInteger ans = new BigInteger("1");
for (int i = 0; i < num.length; i++) {
ans = ans.multiply(BigInteger.valueOf(Integer.valueOf(num[i])));
}
System.out.println(ans);
}
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9b1ba97e80ba4f8a986b214626071815"
}
\ No newline at end of file
# 乘积尾零
如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾有多少个零?
```
5650 4542 3554 473 946 4114 3871 9073 90 4329
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899
1486 5722 3135 1170 4014 5510 5120 729 2880 9019
2049 698 4582 4346 4427 646 9742 7340 1230 7683
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649
6701 6645 1671 5978 2704 9926 295 3125 3878 6785
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074
689 5510 8243 6114 337 4096 8199 7313 3685 211
```
## aop
### before
```cpp
#include <iostream>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int count2 = 0, count5 = 0;
int num;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
{
count5++;
num /= 5;
}
while (num % 2 == 0)
{
count2++;
num /= 2;
}
}
int ans = count2 < count5 ? count2 : count5;
cout << ans;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int count2 = 0, count5 = 0;
int num;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
{
count5++;
num /= 5;
}
while (num % 2 == 0)
{
count2++;
num /= 2;
}
}
int ans = count2 < count5 ? count5 : count2;
cout << ans;
return 0;
}
```
### B
```cpp
int main()
{
int count2 = 0, count5 = 0;
int num;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
{
count5++;
num %= 5;
}
while (num % 2 == 0)
{
count2++;
num %= 2;
}
}
int ans = count2 < count5 ? count2 : count5;
cout << ans;
return 0;
}
```
### C
```cpp
int main()
{
int count2 = 0, count5 = 0;
int num;
for (int i = 0; i < 100; i++)
{
cin >> num;
while (num % 5 == 0)
{
count5++;
num += 5;
}
while (num % 2 == 0)
{
count2++;
num += 2;
}
}
int ans = count2 < count5 ? count2 : count5;
cout << ans;
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"乘积最大"
],
"children": [],
"export": [
"solution.json"
],
"title": "乘积最大"
}
\ No newline at end of file
给定 N 个整数 A1,A2,…AN。
请你从中选出 K 个数,使其乘积最大。
请你求出最大的乘积,由于乘积可能超出整型范围,你只需输出乘积除以 1000000009 的余数。
注意,如果 X<0, 我们定义 X 除以 1000000009 的余数是负(−X)除以 1000000009 的余数,即:0−((0−x)%1000000009)
#### 输入格式
第一行包含两个整数 N 和 K。
以下 N 行每行一个整数 Ai。
#### 输出格式
输出一个整数,表示答案。
#### 数据范围
```
1≤K≤N≤105,
−105≤Ai≤105
```
#### 输入样例1:
```
5 3
-100000
-10000
2
100000
10000
```
#### 输出样例1:
```
999100009
```
#### 输入样例2:
```
5 3
-100000
-100000
-2
-100000
-100000
#### 输出样例2:
-999999829
```
\ No newline at end of file
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
{
ans = num.back();
k = k - 1;
num.pop_back();
}
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 2))
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
}
else
{
ans = ans * num.at(num.size() - 1) * num.at(num.size() - 2) % 1000000009;
num.pop_back();
num.pop_back();
}
k -= 2;
}
cout << ans;
return 0;
}
import java.util.Scanner;
import java.math.*;
public class Main {
private static String s;
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, k;
n = cin.nextInt();
k = cin.nextInt();
s = cin.next();// 不读回车和空格的方式读入
BigDecimal sum = dfs(k, n - 1);
System.out.println(sum);
}
// id是乘号的序号(从左到右1~k);
// dfs(id,r)表示:第id号乘号安放在在第r个空(一共n-1个空)时的最大值
static BigDecimal dfs(int id, int r) {
if (id == 1) {// 安放最后一个(递归概念1号就是递归出口)
BigDecimal sum = BigDecimal.valueOf(0);
for (int i = r; i >= 1; i--) {
BigDecimal x = BigDecimal.valueOf(0);
BigDecimal y = BigDecimal.valueOf(0);
for (int k1 = 0; k1 <= i - 1; k1++) {
char c = s.charAt(k1);
x = x.multiply(BigDecimal.valueOf(10)).add(BigDecimal.valueOf(Integer.parseInt(String.valueOf(c))));
}
for (int k2 = i; k2 <= r; k2++) {
char c = s.charAt(k2);
y = y.multiply(BigDecimal.valueOf(10)).add(BigDecimal.valueOf(Integer.parseInt(String.valueOf(c))));
}
sum = sum.max(x.multiply(y));
}
return sum;
}
BigDecimal maxn = BigDecimal.valueOf(0);
for (int i = r; i >= id; i--) {
BigDecimal temp = dfs(id - 1, i - 1);
BigDecimal tt = BigDecimal.valueOf(0);
for (int kk = i; kk <= r; kk++) {
char c = s.charAt(kk);
tt = tt.multiply(BigDecimal.valueOf(10)).add(BigDecimal.valueOf(Integer.parseInt(String.valueOf(c))));
}
maxn = maxn.max(tt.multiply(temp));
}
return maxn;
}
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ac6de51617074b2baf98b1e70e0cae18"
}
\ No newline at end of file
# 乘积最大
给定 N 个整数 A1,A2,…AN。
请你从中选出 K 个数,使其乘积最大。
请你求出最大的乘积,由于乘积可能超出整型范围,你只需输出乘积除以 1000000009 的余数。
注意,如果 X<0, 我们定义 X 除以 1000000009 的余数是负(−X)除以 1000000009 的余数,即:0−((0−x)%1000000009)
#### 输入格式
第一行包含两个整数 N 和 K。
以下 N 行每行一个整数 Ai。
#### 输出格式
输出一个整数,表示答案。
#### 数据范围
```
1≤K≤N≤105,
−105≤Ai≤105
```
#### 输入样例1:
```
5 3
-100000
-10000
2
100000
10000
```
#### 输出样例1:
```
999100009
```
#### 输入样例2:
```
5 3
-100000
-100000
-2
-100000
-100000
#### 输出样例2:
-999999829
```
## aop
### before
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
{
ans = num.back();
k = k - 1;
num.pop_back();
}
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 2))
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
}
else
{
ans = ans * num.at(num.size() - 1) * num.at(num.size() - 2) % 1000000009;
num.pop_back();
num.pop_back();
}
k -= 2;
}
cout << ans;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
{
ans = num.back();
k = k - 1;
num.pop_back();
}
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size()) * num.at(num.size() - 1))
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
}
else
{
ans = ans * num.at(num.size()) * num.at(num.size() - 1) % 1000000009;
num.pop_back();
num.pop_back();
}
k -= 2;
}
cout << ans;
return 0;
}
```
### B
```cpp
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
{
ans = num.back();
k = k - 1;
num.pop_back();
}
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 1))
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
}
else
{
ans = ans * num.at(num.size() - 1) % 1000000009;
num.pop_back();
num.pop_back();
}
k -= 2;
}
cout << ans;
return 0;
}
```
### C
```cpp
int main()
{
int n, k;
long long ans;
cin >> n >> k;
vector<long long> num;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
num.push_back(temp);
}
sort(num.begin(), num.end());
if (k % 2 != 0)
{
ans = num.back();
k = k - 1;
num.pop_back();
}
else
ans = 1;
while (k > 0)
{
if ((num[0] * num[1]) > num.at(num.size() - 1) * num.at(num.size() - 2))
{
ans = ans * num[0] * num[1] % 1000000009;
num.erase(num.begin(), num.begin() + 1);
}
else
{
ans = ans * num.at(num.size() - 1) % 1000000009;
num.pop_back();
num.pop_back();
}
k -= 2;
}
cout << ans;
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"倍数问题"
],
"children": [],
"export": [
"solution.json"
],
"title": "倍数问题"
}
\ No newline at end of file
#### 题目描述
众所周知,小葱同学擅长计算,尤其擅长计算一个数是否是另外一个数的倍数。但小葱只擅长两个数的情况,当有很多个数之后就会比较苦恼。现在小葱给了你 n 个数,希望你从这 n 个数中找到三个数,使得这三个数的和是 K 的倍数,且这个和最大。数据保证一定有解。
#### 输入格式
从标准输入读入数据。
第一行包括 2 个正整数 n, K。
第二行 n 个正整数,代表给定的 n 个数。
#### 输出格式
输出到标准输出。
输出一行一个整数代表所求的和。
#### 样例输入
```
4 3
1 2 3 4
```
#### 样例输出
```
9
```
#### 样例解释
```
选择2、3、4。
```
\ No newline at end of file
#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;
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);
}
}
}
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;
}
import java.util.Scanner;
public class DFS {
static int max = -1; // 记录最大值
static int n, k;
static int[] num = new int[100010];
static int[] mark = new int[4]; // 记录每一步存储的数字
static boolean[] flag = new boolean[100010]; // 给num一个标记位 是否被使用过
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
n = sc.nextInt();
k = sc.nextInt();
for (int i = 0; i < n; i++) {
num[i] = sc.nextInt();
}
dfs(0);
System.out.println(max);
}
// 使用深搜
public static void dfs(int step) {
// 判断结束条件
if (step == 3) {
int temp = mark[0] + mark[1] + mark[2];
if (temp % k == 0) {
max = Math.max(max, temp);
return;
}
}
for (int i = 0; i < n; i++) {
if (!flag[i]) { // 如果i还没有被记录过
flag[i] = true; // 给 这个数字设置标志位
mark[step] = num[i]; // 在mark中存储 这一位数字
dfs(step + 1);
flag[i] = false; // 循环结束 释放标记位
}
}
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "9d8bb6daa6574c768ee2b54a19748dee"
}
\ No newline at end of file
# 倍数问题
#### 题目描述
众所周知,小葱同学擅长计算,尤其擅长计算一个数是否是另外一个数的倍数。但小葱只擅长两个数的情况,当有很多个数之后就会比较苦恼。现在小葱给了你 n 个数,希望你从这 n 个数中找到三个数,使得这三个数的和是 K 的倍数,且这个和最大。数据保证一定有解。
#### 输入格式
从标准输入读入数据。
第一行包括 2 个正整数 n, K。
第二行 n 个正整数,代表给定的 n 个数。
#### 输出格式
输出到标准输出。
输出一行一个整数代表所求的和。
#### 样例输入
```
4 3
1 2 3 4
```
#### 样例输出
```
9
```
#### 样例解释
```
选择2、3、4。
```
## 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": [
"solution.json"
],
"title": "分数"
}
\ No newline at end of file
1/1 + 1/2 + 1/4 + 1/8 + 1/16 + … 每项是前一项的一半,如果一共有20项,求这个和是多少,结果用分数表示出来。
类似:3/2
当然,这只是加了前2项而已。分子分母要求互质。
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
long pow_2(int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b & 1)
res = x;
b >>= 1;
x = x * x;
}
return res;
}
int gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
cout << gcd(pow_2(20) - 1, pow_2(19)) << endl;
cout << pow_2(20) - 1 << "/" << pow_2(19) << endl;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7a0b6d0f217e4f839911edb82caa4ff6"
}
\ No newline at end of file
# 分数
1/1 + 1/2 + 1/4 + 1/8 + 1/16 + … 每项是前一项的一半,如果一共有20项,求这个和是多少,结果用分数表示出来。
类似:3/2
当然,这只是加了前2项而已。分子分母要求互质。
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
int gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
cout << gcd(pow_2(20) - 1, pow_2(19)) << endl;
cout << pow_2(20) - 1 << "/" << pow_2(19) << endl;
}
```
## 答案
```cpp
long pow_2(int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b & 1)
res *= x;
b >>= 1;
x = x * x;
}
return res;
}
```
## 选项
### A
```cpp
long pow_2(int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b & 1)
res *= x;
b <<= 1;
x = x * x;
}
return res;
}
```
### B
```cpp
long pow_2(int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b && 1)
res *= x;
b <<= 1;
x = x * x;
}
return res;
}
```
### C
```cpp
long pow_2(int b)
{
long x = 2;
long res = 1;
while (b > 0)
{
if (b & 1)
res = x;
b >>= 1;
x = x * x;
}
return res;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"大数乘法"
],
"children": [],
"export": [
"solution.json"
],
"title": "大数乘法"
}
\ No newline at end of file
对于32位字长的机器,大约超过20亿,用int类型就无法表示了,我们可以选择int64类型,但无论怎样扩展,固定的整数类型总是有表达的极限!如果对超级大整数进行精确运算呢?一个简单的办法是:仅仅使用现有类型,但是把大整数的运算化解为若干小整数的运算,即所谓:“分块法”。
![](https://img-blog.csdn.net/20160125091111485)
上图表示了分块乘法的原理。可以把大数分成多段(此处为2段)小数,然后用小数的多次运算组合表示一个大数。可以根据int的承载能力规定小块的大小,比如要把int分成2段,则小块可取10000为上限值。注意,小块在进行纵向累加后,需要进行进位校正。
#include <stdio.h>
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 % base; // 填空
r[0] = n4 / base;
r[1] += r[2] / base; // 填空
r[2] = r[2] % base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
int main(int argc, char *argv[])
{
int x[] = {0, 0, 0, 0};
bigmul(87654321, 12345678, x);
printf("%d%d%d%d\n", x[0], x[1], x[2], x[3]);
return 0;
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "25972bef63434b7aa092c04a009ad893"
}
\ No newline at end of file
# 大数乘法
对于32位字长的机器,大约超过20亿,用int类型就无法表示了,我们可以选择int64类型,但无论怎样扩展,固定的整数类型总是有表达的极限!如果对超级大整数进行精确运算呢?一个简单的办法是:仅仅使用现有类型,但是把大整数的运算化解为若干小整数的运算,即所谓:“分块法”。
![](https://img-blog.csdn.net/20160125091111485)
上图表示了分块乘法的原理。可以把大数分成多段(此处为2段)小数,然后用小数的多次运算组合表示一个大数。可以根据int的承载能力规定小块的大小,比如要把int分成2段,则小块可取10000为上限值。注意,小块在进行纵向累加后,需要进行进位校正。
## aop
### before
```cpp
#include <stdio.h>
```
### after
```cpp
int main(int argc, char *argv[])
{
int x[] = {0, 0, 0, 0};
bigmul(87654321, 12345678, x);
printf("%d%d%d%d\n", x[0], x[1], x[2], x[3]);
return 0;
}
```
## 答案
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 % base;
r[0] = n4 / base;
r[1] += r[2] / base;
r[2] = r[2] % base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```
## 选项
### A
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 % base;
r[0] = n4 / base;
r[1] += r[2] % base;
r[2] = r[2] / base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```
### B
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 / base + n4 / base;
r[0] = n4 / base;
r[1] += r[2] / base;
r[2] = r[2] % base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```
### C
```cpp
void bigmul(int x, int y, int r[])
{
int base = 10000;
int x2 = x / base;
int x1 = x % base;
int y2 = y / base;
int y1 = y % base;
int n1 = x1 * y1;
int n2 = x1 * y2;
int n3 = x2 * y1;
int n4 = x2 * y2;
r[3] = n1 % base;
r[2] = n1 / base + n2 % base + n3 % base;
r[1] = n2 / base + n3 % base + n4 / base;
r[0] = n4 / base;
r[1] += r[2] / base;
r[2] = r[2] % base;
r[0] += r[1] / base;
r[1] = r[1] % base;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"大衍数列"
],
"children": [],
"export": [
"solution.json"
],
"title": "大衍数列"
}
\ No newline at end of file
中国古代文献中,曾记载过“大衍数列”, 主要用于解释中国传统文化中的太极衍生原理。
它的前几项是:```0、2、4、8、12、18、24、32、40、50 …```
其规律是:对偶数项,是序号平方再除2,奇数项,是序号平方减1再除2。
以下的代码打印出了大衍数列的前 100 项。
\ No newline at end of file
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
\ No newline at end of file
public class Main {
public static void main(String[] args) {
for (int i = 1; i < 100; i++) {
if (i % 2 == 0) // 填空 //i%2==0偶数项
System.out.println(i * i / 2);
else// 奇数项
System.out.println((i * i - 1) / 2);
}
}
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "4eb77452b33a4fd8a89fef6d2be77522"
}
\ No newline at end of file
# 大衍数列
中国古代文献中,曾记载过“大衍数列”, 主要用于解释中国传统文化中的太极衍生原理。
它的前几项是:```0、2、4、8、12、18、24、32、40、50 …```
其规律是:对偶数项,是序号平方再除2,奇数项,是序号平方减1再除2。
以下的代码打印出了大衍数列的前 100 项。
## aop
### before
```cpp
#include <stdio.h>
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
```
## 选项
### A
```cpp
int main()
{
int i;
for (i = 1; i < 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
```
### B
```cpp
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i / 2 == 0)
printf("%d ", i * i / 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
```
### C
```cpp
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i % 2 == 0)
printf("%d ", i * i % 2);
else
printf("%d ", (i * i - 1) / 2);
}
printf("\n");
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"成绩分析"
],
"children": [],
"export": [
"solution.json"
],
"title": "成绩分析"
}
\ No newline at end of file
#### 问题描述
小蓝给学生们组织了一场考试,卷面总分为100分,每个学生的得分都是一个0到100的整数。
请计算这次考试的最高分、最低分和平均分。
#### 输入格式
输入的第一行包含一个整数n,表示考试人数。
接下来n行,每行包含一个0至100的整数,表示一个学生的得分。
#### 输出格式
输出三行。
第一行包含一个整数,表示最高分。
第二行包含一个整数,表示最低分。
第三行包含一个实数,四舍五入保留正好两位小数,表示平均分。
#### 样例输入
```
7
80
92
56
74
88
99
10
```
#### 样例输出
```
99
10
71.29
```
\ No newline at end of file
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score > top)
top = score;
if (score < low)
low = score;
sum += score;
}
printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n));
return 0;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
//成绩分析(利用集合)
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
int n = scan.nextInt();
double sum = 0;
for (int i = 0; i < n; i++) {
list.add(scan.nextInt());
sum = sum + list.get(i);
}
Collections.sort(list);
System.out.println(Collections.max(list));
System.out.println(Collections.min(list));
System.out.println(String.format("%.2f", sum / n));
scan.close();
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "2b6d7a9435784fc89e53c761270247b0"
}
\ No newline at end of file
# 成绩分析
#### 问题描述
小蓝给学生们组织了一场考试,卷面总分为100分,每个学生的得分都是一个0到100的整数。
请计算这次考试的最高分、最低分和平均分。
#### 输入格式
输入的第一行包含一个整数n,表示考试人数。
接下来n行,每行包含一个0至100的整数,表示一个学生的得分。
#### 输出格式
输出三行。
第一行包含一个整数,表示最高分。
第二行包含一个整数,表示最低分。
第三行包含一个实数,四舍五入保留正好两位小数,表示平均分。
#### 样例输入
```
7
80
92
56
74
88
99
10
```
#### 样例输出
```
99
10
71.29
```
## aop
### before
```cpp
#include <stdio.h>
#include <iostream>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score > top)
top = score;
if (score < low)
low = score;
sum += score;
}
printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n));
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score > top)
top = score;
if (score < low)
low = score;
sum += score;
}
printf("%d\n%d\n%.f", top, low, (sum * 1.0 / n));
return 0;
}
```
### B
```cpp
int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score > top)
score = top;
if (score < low)
score = low;
sum += score;
}
printf("%d\n%d\n%.2lf", top, low, (sum * 1.0 / n));
return 0;
}
```
### C
```cpp
int main()
{
int n;
cin >> n;
int sum = 0;
int top = 0;
int low = 100;
int score;
for (int i = 0; i < n; i++)
{
cin >> score;
if (score < top)
top = score;
if (score > low)
low = score;
sum += score;
}
printf("%d\n%d\n%d", top, low, (sum / n));
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"成绩统计"
],
"children": [],
"export": [
"solution.json"
],
"title": "成绩统计"
}
\ No newline at end of file
#### 问题描述
编写一个程序,建立了一条单向链表,每个结点包含姓名、学号、英语成绩、数学成绩和C++成绩,并通过链表操作平均最高的学生和平均分最低的学生并且输出。
#### 输入格式
输入n+1行,第一行输入一个正整数n,表示学生数量;接下来的n行每行输入5个数据,分别表示姓名、学号、英语成绩、数学成绩和C++成绩。注意成绩有可能会有小数。
#### 输出格式
输出两行,第一行输出平均成绩最高的学生姓名。第二行输出平均成绩最低的学生姓名。
#### 样例输入
```
2
yx1 1 45 67 87
yx2 2 88 90 99
```
#### 样例输出
```
yx2
yx1
```
\ No newline at end of file
#include <iostream>
using namespace std;
int main()
{
struct student
{
string xm;
int xh;
double yy;
double sx;
double cpp;
};
student a[1000];
int n;
double sum = 0, min = 301, max = 0;
string mins, maxs;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp;
sum = a[i].yy + a[i].sx + a[i].cpp;
if (min > sum)
{
min = sum;
mins = a[i].xm;
}
if (max < sum)
{
max = sum;
maxs = a[i].xm;
}
}
cout << maxs << endl
<< mins;
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String Max = ""; // 成绩最高
String Min = ""; // 成绩最低
double maxavg = Integer.MIN_VALUE; // 最大平均值
double minavg = Integer.MAX_VALUE; // 最小平均值
for (int i = 0; i < n; i++) {
String Name = scanner.next(); // 姓名
String Id = scanner.next(); // 学号
int English = scanner.nextInt(); // 英语
int Mathematics = scanner.nextInt(); // 数学
int Cplus = scanner.nextInt(); // C++
double Avg = (English + Mathematics + Cplus) / 3; // 平均成绩
if (maxavg < Avg) { // 最大平均值<平均成绩
Max = Name; // 最大值=姓名
maxavg = Avg; // 最大平均值=平均成绩
}
if (minavg > Avg) { // 最小平均值>平均成绩
Min = Name; // 最小值=姓名
minavg = Avg; // 最小平均值=平均成绩
}
}
System.out.println(Max); // 输出成绩最高者
System.out.println(Min); // 输出成绩最低者
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "adbfdfc38c824ce185e91062698404d0"
}
\ No newline at end of file
# 成绩统计
#### 问题描述
编写一个程序,建立了一条单向链表,每个结点包含姓名、学号、英语成绩、数学成绩和C++成绩,并通过链表操作平均最高的学生和平均分最低的学生并且输出。
#### 输入格式
输入n+1行,第一行输入一个正整数n,表示学生数量;接下来的n行每行输入5个数据,分别表示姓名、学号、英语成绩、数学成绩和C++成绩。注意成绩有可能会有小数。
#### 输出格式
输出两行,第一行输出平均成绩最高的学生姓名。第二行输出平均成绩最低的学生姓名。
#### 样例输入
```
2
yx1 1 45 67 87
yx2 2 88 90 99
```
#### 样例输出
```
yx2
yx1
```
## aop
### before
```cpp
#include <iostream>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
struct student
{
string xm;
int xh;
double yy;
double sx;
double cpp;
};
student a[1000];
int n;
double sum = 0, min = 301, max = 0;
string mins, maxs;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp;
sum = a[i].yy + a[i].sx + a[i].cpp;
if (min > sum)
{
min = sum;
mins = a[i].xm;
}
if (max < sum)
{
max = sum;
maxs = a[i].xm;
}
}
cout << maxs << endl
<< mins;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
struct student
{
string xm;
int xh;
double yy;
double sx;
double cpp;
};
student a[1000];
int n;
double sum = 0, min = 301, max = 0;
string mins, maxs;
cin >> n;
for (int i = 1; i < n; i++)
{
cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp;
sum = a[i].yy + a[i].sx + a[i].cpp;
if (min > sum)
{
min = sum;
mins = a[i].xm;
}
if (max < sum)
{
max = sum;
maxs = a[i].xm;
}
}
cout << maxs << endl
<< mins;
return 0;
}
```
### B
```cpp
int main()
{
struct student
{
string xm;
int xh;
double yy;
double sx;
double cpp;
};
student a[1000];
int n;
double sum = 0, min = 301, max = 0;
string mins, maxs;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp;
sum = a[i].yy + a[i].sx + a[i].cpp;
if (min > sum)
{
min = sum;
mins = a[i]->xm;
}
if (max < sum)
{
max = sum;
maxs = a[i]->xm;
}
cout << maxs << endl
<< mins;
return 0;
}
}
```
### C
```cpp
int main()
{
struct student
{
string xm;
int xh;
double yy;
double sx;
double cpp;
};
student a[1000];
int n;
double sum = 0, min = 301, max = 0;
string mins, maxs;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].xm >> a[i].xh >> a[i].yy >> a[i].sx >> a[i].cpp;
sum = a[i].yy + a[i].sx + a[i].cpp;
if (min > sum)
{
min = sum;
mins = a[i].xm;
}
if (max < sum)
{
max = sum;
maxs = a[i].xm;
}
}
cout << mins << endl
<< maxs;
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"斐波那契"
],
"children": [],
"export": [
"solution.json"
],
"title": "斐波那契"
}
\ No newline at end of file
Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。
当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少。
#### 输入格式
输入包含一个整数n。
输出格式
输出一行,包含一个整数,表示Fn除以10007的余数。
说明:在本题中,答案是要求Fn除以10007的余数,因此我们只要能算出这个余数即可,而不需要先计算出Fn的准确值,再将计算的结果除以10007取余数,直接计算余数往往比先算出原数再取余简单。
#### 样例输入
```
10
```
#### 样例输出
```
55
```
#### 样例输入
```
22
```
#### 样例输出
```
7704
```
#### 数据规模与约定
```
1 <= n <= 1,000,000。
```
\ No newline at end of file
#include <stdio.h>
int main()
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i];
}
if (n > 2)
printf("%d", b);
else
printf("1");
return 0;
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "6101d9e66d1d4c5c89f910fa3ed95ad7"
}
\ No newline at end of file
# 斐波那契
Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。
当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少。
#### 输入格式
输入包含一个整数n。
输出格式
输出一行,包含一个整数,表示Fn除以10007的余数。
说明:在本题中,答案是要求Fn除以10007的余数,因此我们只要能算出这个余数即可,而不需要先计算出Fn的准确值,再将计算的结果除以10007取余数,直接计算余数往往比先算出原数再取余简单。
#### 样例输入
```
10
```
#### 样例输出
```
55
```
#### 样例输入
```
22
```
#### 样例输出
```
7704
```
#### 数据规模与约定
```
1 <= n <= 1,000,000。
```
## aop
### before
```cpp
#include <stdio.h>
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i];
}
if (n > 2)
printf("%d", b);
else
printf("1");
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i] + 1;
}
if (n > 2)
printf("%d", b);
else
printf("1");
return 0;
}
```
### B
```cpp
int main()
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i - 1];
}
if (n > 2)
printf("%d", b);
else
printf("1");
return 0;
}
```
### C
```cpp
int main()
{
int n, b;
scanf("%d", &n);
int a[n];
a[0] = a[1] = 1;
for (int i = 2; i < n; i++)
{
a[i] = (a[i - 1] + a[i - 2]) % 10007;
b = a[i - 2];
}
if (n > 2)
printf("%d", b);
else
printf("1");
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"方阵转置"
],
"children": [],
"export": [
"solution.json"
],
"title": "方阵转置"
}
\ No newline at end of file
#### 问题描述
给定一个n×m矩阵相乘,求它的转置。其中1≤n≤20,1≤m≤20,矩阵中的每个元素都在整数类型(4字节)的表示范围内。
#### 输入格式
第一行两个整数n和m;
第二行起,每行m个整数,共n行,表示n×m的矩阵。数据之间都用一个空格分隔。
#### 输出格式
共m行,每行n个整数,数据间用一个空格分隔,表示转置后的矩阵。
#### 样例输入
```
2 4
34 76 -54 7
-4 5 23 9
```
#### 样例输出
```
34 -4
76 5
-54 23
7 9
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7517db8b11ca4582a2614dea1e548e67"
}
\ No newline at end of file
# 方阵转置
#### 问题描述
给定一个n×m矩阵相乘,求它的转置。其中1≤n≤20,1≤m≤20,矩阵中的每个元素都在整数类型(4字节)的表示范围内。
#### 输入格式
第一行两个整数n和m;
第二行起,每行m个整数,共n行,表示n×m的矩阵。数据之间都用一个空格分隔。
#### 输出格式
共m行,每行n个整数,数据间用一个空格分隔,表示转置后的矩阵。
#### 样例输入
```
2 4
34 76 -54 7
-4 5 23 9
```
#### 样例输出
```
34 -4
76 5
-54 23
7 9
```
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = 0; i < n; i++)
{
for (j = m; j > 0; j--)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
```
### B
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = n; i > 0; i--)
{
for (j = 0; j < m; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
```
### C
```cpp
int main()
{
int m, n;
int a[20][20];
int i, j;
cin >> m >> n;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[j][i];
}
}
for (i = n; i > 0; i--)
{
for (j = m; j > 0; j--)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"次数差"
],
"children": [],
"export": [
"solution.json"
],
"title": "次数差"
}
\ No newline at end of file
#### 问题描述
x星球有26只球队,分别用 a ~ z 的26个字母代表。他们总是不停地比赛。
在某一赛段,哪个球队获胜了,就记录下代表它的字母,这样就形成一个长长的串。
国王总是询问:获胜次数最多的和获胜次数最少的有多大差距?
(当然,他不关心那些一次也没获胜的,认为他们在怠工罢了)
#### 输入格式
一个串,表示球队获胜情况(保证串的长度<1000)
#### 输出格式
要求输出一个数字,表示出现次数最多的字母比出现次数最少的字母多了多少次。
#### 样例输入1
```
abaabcaa
```
#### 样例输出1
```
4
```
#### 提示
```
a 出现 5 次,最多;c 出现1次,最少。
5 - 1 = 4
```
#### 样例输入2
```
bbccccddaaaacccc
```
#### 样例输出2
```
6
```
\ No newline at end of file
#include <stdio.h>
#include <string.h>
int main() //计数排序
{
char s[1000];
scanf("%s", &s);
int len = strlen(s); //获取字符串s的长度
int helper[256] = {0}; //ascll范围在0~255之间(包括0和255)
int max = 0, min = len;
for (int i = 0; i < len; i++)
{
helper[s[i]]++; //计数
}
for (int i = 0; i < 256; i++)
{
if (helper[i] > max)
{
max = helper[i];
}
if (helper[i] < min && helper[i] != 0)
{
min = helper[i];
}
}
printf("%d\n", max - min);
return 0;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Map<Character, Integer> map = new HashMap<Character, Integer>();
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
for (int i = 0; i < str.length(); i++) {
char key = str.charAt(i);
// 如果没有这个键,则添加键并赋值为1
if (!map.containsKey(key)) {
map.put(key, 1);
}
// 否则获取当前值,自增1
else {
int value = map.get(str.charAt(i));
map.put(key, ++value);
}
}
// 使用HashMap的方法values(),取出所有的Value集合构造List
List<Integer> sorted = new ArrayList<Integer>(map.values());
// 然后使用Collections.sort排序
Collections.sort(sorted);
// 用最大的值减去最小的值,得到差
int difference = sorted.get(sorted.size() - 1) - sorted.get(0);
System.out.print(difference);
}
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "b7458cb84ddc4119833ec9d96b260e7b"
}
\ No newline at end of file
# 次数差
#### 问题描述
x星球有26只球队,分别用 a ~ z 的26个字母代表。他们总是不停地比赛。
在某一赛段,哪个球队获胜了,就记录下代表它的字母,这样就形成一个长长的串。
国王总是询问:获胜次数最多的和获胜次数最少的有多大差距?
(当然,他不关心那些一次也没获胜的,认为他们在怠工罢了)
#### 输入格式
一个串,表示球队获胜情况(保证串的长度<1000)
#### 输出格式
要求输出一个数字,表示出现次数最多的字母比出现次数最少的字母多了多少次。
#### 样例输入1
```
abaabcaa
```
#### 样例输出1
```
4
```
#### 提示
```
a 出现 5 次,最多;c 出现1次,最少。
5 - 1 = 4
```
#### 样例输入2
```
bbccccddaaaacccc
```
#### 样例输出2
```
6
```
## aop
### before
```cpp
#include <stdio.h>
#include <string.h>
```
### after
```cpp
```
## 答案
```cpp
int main()
{
char s[1000];
scanf("%s", &s);
int len = strlen(s);
int helper[256] = {0};
int max = 0, min = len;
for (int i = 0; i < len; i++)
{
helper[s[i]]++;
}
for (int i = 0; i < 256; i++)
{
if (helper[i] > max)
{
max = helper[i];
}
if (helper[i] < min && helper[i] != 0)
{
min = helper[i];
}
}
printf("%d\n", max - min);
return 0;
}
```
## 选项
### A
```cpp
int main()
{
char s[1000];
scanf("%s", &s);
int len = strlen(s);
int helper[256] = {0};
int max = 0, min = len;
for (int i = 0; i < len; i++)
{
helper[s[i]]++;
}
for (int i = 0; i < 256; i++)
{
if (helper[i] > max)
{
max = helper[i];
}
if (helper[i] < min)
{
min = helper[i];
}
}
printf("%d\n", max - min);
return 0;
}
```
### B
```cpp
int main()
{
char s[1000];
scanf("%s", &s);
int len = strlen(s);
int helper[256] = {0};
int max = 0, min = len;
for (int i = 0; i < len; i++)
{
helper[s[i]]++;
}
for (int i = 0; i < 256; i++)
{
if (helper[i] > max)
{
max = helper[i];
}
if (helper[i] < min && helper[i] == 0)
{
min = helper[i];
}
}
printf("%d\n", max - min);
return 0;
}
```
### C
```cpp
int main()
{
char s[1000];
scanf("%s", &s);
int len = strlen(s);
int helper[256] = {0};
int max = 0, min = len;
for (int i = 0; i < len; i++)
{
helper[s[i]]++;
}
for (int i = 0; i < 256; i++)
{
if (helper[i] < max)
{
max = helper[i];
}
if (helper[i] > min)
{
min = helper[i];
}
}
printf("%d\n", max - min);
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"比酒量"
],
"children": [],
"export": [
"solution.json"
],
"title": "比酒量"
}
\ No newline at end of file
有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。再打开一瓶酒平分,又有倒下的,
再次重复......
直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。当第4瓶酒平分喝下后,大家都倒下了。
等船长醒来,发现海盗船搁浅了。他在航海日志中写到:“......昨天,我正好喝了一瓶.......奉劝大家,开船不喝酒,喝酒别开船......”
请你根据这些信息,推断开始有多少人,每一轮喝下来还剩多少人。
如果有多个可能的答案,请列出所有答案,每个答案占一行。
格式是:人数,人数,...
例如,有一种可能是:```20,5,4,2,0```
#include <cstdio>
#include <iostream>
using namespace std;
int d, a1[4];
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;
}
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;
}
\ No newline at end of file
public class Main {
public static void main(String[] args) {
for (int a = 20; a > 0; a--) {
for (int b = a - 1; b > 0; b--) {
for (int c = b - 1; c > 0; c--) {
for (int d = c - 1; d > 0; d--) {
int a1 = a * b * c;
int a2 = a * b * d;
int a3 = a * c * d;
int a4 = b * c * d;
int n = a * b * c * d;
if (a1 + a2 + a3 + a4 == n) {
System.out.println(a + "," + b + "," + c + "," + d);
}
}
}
}
}
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "7b60c9f0124f416584bf71dc1ba45047"
}
\ No newline at end of file
# 比酒量
有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。再打开一瓶酒平分,又有倒下的,
再次重复......
直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。当第4瓶酒平分喝下后,大家都倒下了。
等船长醒来,发现海盗船搁浅了。他在航海日志中写到:“......昨天,我正好喝了一瓶.......奉劝大家,开船不喝酒,喝酒别开船......”
请你根据这些信息,推断开始有多少人,每一轮喝下来还剩多少人。
如果有多个可能的答案,请列出所有答案,每个答案占一行。
格式是:人数,人数,...
例如,有一种可能是:```20,5,4,2,0```
## 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;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"猜字母"
],
"children": [],
"export": [
"solution.json"
],
"title": "猜字母"
}
\ No newline at end of file
把abcd...s共19个字母组成的序列重复拼接106次,得到长度为2014的串。
接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母。
得到的新串再进行删除奇数位置字母的动作。如此下去,最后只剩下一个字母,请写出该字母。
\ No newline at end of file
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<char> vc1;
int i;
for (i = 0; i < 2014; i++)
vc1.push_back('a' + (i % 19));
while (vc1.size() != 1)
{
vector<char> vc2;
cout << vc1.size() << endl;
for (i = 1; i < vc1.size(); i += 2)
vc2.push_back(vc1[i]);
vc1.assign(vc2.begin(), vc2.end());
cout << vc1.size() << endl;
}
cout << vc1[0] << endl;
return 0;
}
\ No newline at end of file
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
String string = "", string1 = "";
for (int i = 0; i < 2014; i++) {
string += (char) ('a' + (i % 19));
}
while (string.length() != 1) {
for (int i = 0; i < string.length(); i++) {
if (i % 2 == 1) {
string1 += string.charAt(i);
}
}
string = string1;
string1 = "";
}
System.out.println(string);
}
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "1f01880602b0429abcadecb4a3c629ab"
}
\ No newline at end of file
# 猜字母
把abcd...s共19个字母组成的序列重复拼接106次,得到长度为2014的串。
接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母。
得到的新串再进行删除奇数位置字母的动作。如此下去,最后只剩下一个字母,请写出该字母。
## aop
### before
```cpp
#include <iostream>
#include <vector>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
vector<char> vc1;
int i;
for (i = 0; i < 2014; i++)
vc1.push_back('a' + (i % 19));
while (vc1.size() != 1)
{
vector<char> vc2;
cout << vc1.size() << endl;
for (i = 1; i < vc1.size(); i += 2)
vc2.push_back(vc1[i]);
vc1.assign(vc2.begin(), vc2.end());
cout << vc1.size() << endl;
}
cout << vc1[0] << endl;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
vector<char> vc1;
int i;
for (i = 0; i < 2014; i++)
vc1.push_back('a' + (i % 19));
while (vc1.size() != 1)
{
vector<char> vc2;
cout << vc1.size() << endl;
for (i = 0; i < vc1.size(); i++)
vc2.push_back(vc1[i]);
vc1.assign(vc2.begin(), vc2.end());
cout << vc1.size() << endl;
}
cout << vc1[0] << endl;
return 0;
}
```
### B
```cpp
int main()
{
vector<char> vc1;
int i;
for (i = 0; i < 2014; i++)
vc1.push_back('a' + (i % 19));
while (vc1.size() != 1)
{
vector<char> vc2;
cout << vc1.size() << endl;
for (i = 0; i < vc1.size(); i += 1)
vc2.push_back(vc1[i]);
vc1.assign(vc2.begin(), vc2.end());
cout << vc1.size() << endl;
}
cout << vc1[0] << endl;
return 0;
}
```
### C
```cpp
int main()
{
vector<char> vc1;
int i;
for (i = 0; i < 2014; i++)
vc1.push_back('a' + (i % 19));
while (vc1.size() != 1)
{
vector<char> vc2;
cout << vc1.size() << endl;
for (i = 0; i < vc1.size(); i += 2)
vc2.push_back(vc1[i]);
vc1.assign(vc2.begin(), vc2.end());
cout << vc1.size() << endl;
}
cout << vc1[0] << endl;
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"猜年龄"
],
"children": [],
"export": [
"solution.json"
],
"title": "猜年龄"
}
\ No newline at end of file
美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。
一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”
请你推算一下,他当时到底有多年轻。
#include <iostream>
using namespace std;
int main()
{
for (int i = 11; i < 35; i++)
{
int i1 = i * i * i;
int i2 = i * i1;
if ((i1 >= 1000 && i1 < 10000) && (i2 >= 100000 && i2 < 1000000))
cout << i << " " << i1 << " " << i2 << endl;
}
return 0;
}
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static boolean judge(int x) {
int a = x * x * x;
int b = x * x * x * x;
boolean vis[] = new boolean[10];
if (a < 1000 || a > 9999)
return false;
if (b < 100000 || b > 999999)
return false;
while (a > 0) {
vis[a % 10] = true;
a /= 10;
}
while (b > 0) {
vis[b % 10] = true;
b /= 10;
}
for (int i = 0; i < 10; i++)
if (!vis[i])
return false;
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
for (int i = 1; i <= 1000; i++) {
if (judge(i)) {
System.out.println(i);
break;
}
}
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "ee8e974a2ca246ea9fa24d6f631dbc73"
}
\ No newline at end of file
# 猜年龄
美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。
一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”
请你推算一下,他当时到底有多年轻。
## aop
### before
```cpp
```
### after
```cpp
#include <iostream>
using namespace std;
int main()
{
for (int i = 11; i < 35; i++)
{
int i1 = i * i * i;
int i2 = i * i1;
if ((i1 >= 1000 && i1 < 10000) && (i2 >= 100000 && i2 < 1000000))
cout << i << " " << i1 << " " << i2 << endl;
}
return 0;
}
```
## 答案
```cpp
18
```
## 选项
### A
```cpp
19
```
### B
```cpp
20
```
### C
```cpp
21
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"第39级台阶"
],
"children": [],
"export": [
"solution.json"
],
"title": "第39级台阶"
}
\ No newline at end of file
小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级!
站在台阶前,他突然又想着一个问题:
如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢?
请你利用计算机的优势,帮助小明寻找答案。
#include <iostream>
#define LEFT 0
#define RIGHT 1
using namespace std;
int stage[40][2];
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT];
stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT];
}
cout << stage[39][RIGHT] << endl;
return 0;
}
\ No newline at end of file
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f3312f1da7a64f55b8db8f11cd9c3147"
}
\ No newline at end of file
# 第39级台阶
小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级!
站在台阶前,他突然又想着一个问题:
如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢?
请你利用计算机的优势,帮助小明寻找答案。
## aop
### before
```cpp
#include <iostream>
#define LEFT 0
#define RIGHT 1
using namespace std;
int stage[40][2];
```
### after
```cpp
```
## 答案
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT];
stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT];
}
cout << stage[39][RIGHT] << endl;
return 0;
}
```
## 选项
### A
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
stage[i][LEFT] = stage[i - 1][RIGHT] + stage[i - 2][RIGHT];
stage[i][RIGHT] = stage[i - 1][LEFT] + stage[i - 2][LEFT];
}
cout << stage[39][LEFT] << endl;
return 0;
}
```
### B
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
stage[i][LEFT] = stage[i + 1][RIGHT] + stage[i - 1][RIGHT];
stage[i][RIGHT] = stage[i + 1][LEFT] + stage[i - 1][LEFT];
}
cout << stage[39][RIGHT] << endl;
return 0;
}
```
### C
```cpp
int main()
{
int i;
stage[1][LEFT] = 1;
stage[1][RIGHT] = 0;
stage[2][LEFT] = 1;
stage[2][RIGHT] = 1;
for (i = 3; i <= 39; i++)
{
stage[i][LEFT] = stage[i + 1][RIGHT] + stage[i - 1][RIGHT];
stage[i][RIGHT] = stage[i + 1][LEFT] + stage[i - 1][LEFT];
}
cout << stage[39][LEFT] << endl;
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"第几个幸运数"
],
"children": [],
"export": [
"solution.json"
],
"title": "第几个幸运数"
}
\ No newline at end of file
到x星球旅行的游客都被发给一个整数,作为游客编号。
x星的国王有个怪癖,他只喜欢数字3,5和7。
国王规定,游客的编号如果只含有因子:3,5,7,就可以获得一份奖品。
我们来看前10个幸运数字是:
3 5 7 9 15 21 25 27 35 45
因而第11个幸运数字是:49
小明领到了一个幸运数字 59084709587505,他去领奖的时候,人家要求他准确地说出这是第几个幸运数字,否则领不到奖品。
请你帮小明计算一下,59084709587505是第几个幸运数字。
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
int main()
{
set<long long> st;
priority_queue<long long, vector<long long>, greater<long long>> pq;
const int ok[3] = {3, 5, 7};
st.insert(1);
pq.push(1);
int times = 0;
while (true)
{
long long lucky = pq.top();
pq.pop();
if (lucky == 59084709587505)
{ //49
cout << times << endl;
return 0;
}
times++;
for (int i = 0; i < 3; i++)
{
long long b = lucky * ok[i];
if (!st.count(b))
{
st.insert(b);
pq.push(b);
}
}
}
return 0;
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册