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

update dir sstructure

上级 cb9d4f26

要显示的变更太多。

To preserve performance only 1000 of 1000+ files are displayed.
{
"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": []
}
\ No newline at end of file
#### 问题描述
给定一棵包含 N 个节点的二叉树,节点编号是 1 ∼ N。其中 i 号节点具有权值 W i ,并且这些节点的权值恰好形成了一棵排序二叉树 (BST)。
现在给定一个节点编号 K,小明想知道,在这 N 个权值以外,有多少个整数 X (即 X 不等于任何 W i ) 满足:给编号为 K 的节点增加一个权值为 X 的子节点,仍可以得到一棵 BST。
例如在下图中,括号外的数字表示编号、括号内的数字表示权值。即编号1 ∼ 4 的节点权值依次是 0、10、20、30。
![](https://img-blog.csdnimg.cn/20201010210318917.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L01pbGtMZW9uZw==,size_16,color_FFFFFF,t_70#pic_center)
如果 K = 1,那么答案为 0。因为 1 号节点已经有左右子节点,不能再增加子节点了。
如果 K = 2,那么答案为无穷多。因为任何一个负数都可以作为 2 的左子节点。
如果 K = 3,那么答案为 9。因为 X = 11,12,··· ,19 都可以作为 3 的左子节点。
#### 输入格式
第一行包含 2 个整数 N 和 K。
以下 N 行每行包含 2 个整数,其中第 i 行是编号为 i 的节点的父节点编号P i 和权值 W i 。注意 P i = 0 表示 i 是根节点。
输入保证是一棵 BST。
#### 输出格式
一个整数代表答案。如果答案是无穷多,输出 −1。
#### 样例输入
```
4 3
0 10
1 0
1 20
3 30
```
#### 样例输出
```
9
```
#### 评测用例规模与约定
对于 60% 的评测用例,1 ≤ K ≤ N ≤ 100,0 ≤ W i ≤ 200,且 W i 各不相同。
对于所有评测用例,1 ≤ K ≤ N ≤ 10000,0 ≤ W i ≤ 100000000,且 W i 各不相同。
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class _09BST插入节点问题 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] parent = new int[n];
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < n; i++) {
parent[i] = sc.nextInt();
map.put(i + 1, sc.nextInt());
}
ArrayList<Integer> childs = new ArrayList<Integer>();
int rootWeight = map.get(1);
int kWeight = map.get(k);
for (int i = 0; i < parent.length; i++) {
if (k == parent[i])
childs.add(map.get(i + 1));
}
// 1.parents不存在的节点就是叶子节点,叶子节点的答案是无穷大
if (childs.size() == 0) {
System.out.println("叶子节点");
System.out.println(-1);
return;
}
// 2. 已经有左右孩子,答案是0
else if (childs.size() == 2) {
System.out.println("已经有左右孩子了");
System.out.println(0);
return;
}
// 3. 在右子树:k节点有左无右时为-1; 在左子树:k几点有右无左为-1
else if (childs.size() == 1 && (kWeight > rootWeight && childs.get(0) < kWeight)
|| (kWeight < rootWeight && childs.get(0) > kWeight)) {
System.out.println(-1);
return;
} else {
int fatherWeight = map.get(parent[k - 1]);
System.out.println(Math.abs(kWeight - fatherWeight) - 1);
return;
}
}
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
附件 prog.txt 中是一个用某种语言写的程序。附件在本文的末尾。
其中 REPEAT k 表示一个次数为 k 的循环。循环控制的范围由缩进表达,从次行开始连续的缩进比该行多的(前面的空白更长的)为循环包含的内容。
![](https://img-blog.csdnimg.cn/20210320200704647.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0MDEzMjQ3,size_16,color_FFFFFF,t_70)
该片段中从 A = A + 4 所在的行到 A = A + 8 所在的行都在第一行的循环两次中。
REPEAT 6: 所在的行到 A = A + 7 所在的行都在 REPEAT 5: 循环中。
A = A + 5 实际总共的循环次数是 2 × 5 × 6 = 60 次。
请问该程序执行完毕之后,A 的值是多少?
题目给出的 prog.txt 文件:
```
A = 0
REPEAT 2:
A = A + 4
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 7
REPEAT 6:
A = A + 7
REPEAT 4:
A = A + 2
A = A + 7
A = A + 2
REPEAT 7:
REPEAT 4:
A = A + 8
A = A + 7
A = A + 4
A = A + 5
A = A + 8
REPEAT 8:
A = A + 5
REPEAT 1:
A = A + 2
REPEAT 7:
A = A + 5
A = A + 5
REPEAT 2:
REPEAT 3:
A = A + 1
A = A + 1
REPEAT 5:
A = A + 1
REPEAT 9:
REPEAT 6:
A = A + 5
A = A + 1
REPEAT 6:
A = A + 2
A = A + 8
A = A + 3
REPEAT 2:
A = A + 5
REPEAT 3:
A = A + 9
REPEAT 1:
A = A + 4
REPEAT 2:
A = A + 9
REPEAT 1:
A = A + 6
A = A + 6
A = A + 4
REPEAT 3:
A = A + 7
A = A + 1
REPEAT 2:
A = A + 3
REPEAT 5:
A = A + 2
A = A + 5
A = A + 2
A = A + 4
A = A + 3
REPEAT 4:
A = A + 4
A = A + 3
A = A + 7
REPEAT 5:
REPEAT 4:
A = A + 5
A = A + 7
REPEAT 5:
A = A + 3
REPEAT 3:
A = A + 3
A = A + 1
A = A + 8
A = A + 2
REPEAT 9:
A = A + 5
REPEAT 1:
A = A + 5
A = A + 2
A = A + 8
A = A + 6
REPEAT 3:
REPEAT 4:
A = A + 9
REPEAT 5:
A = A + 2
A = A + 1
REPEAT 9:
A = A + 9
A = A + 2
REPEAT 1:
A = A + 6
A = A + 8
REPEAT 2:
A = A + 9
A = A + 4
A = A + 7
REPEAT 2:
REPEAT 7:
A = A + 3
A = A + 5
REPEAT 3:
A = A + 5
A = A + 3
A = A + 6
A = A + 4
REPEAT 9:
A = A + 2
A = A + 8
A = A + 2
A = A + 3
REPEAT 2:
REPEAT 8:
A = A + 5
A = A + 1
A = A + 6
A = A + 1
A = A + 2
REPEAT 6:
REPEAT 1:
A = A + 3
REPEAT 1:
A = A + 2
REPEAT 4:
A = A + 7
A = A + 1
A = A + 8
REPEAT 6:
A = A + 5
REPEAT 6:
A = A + 3
REPEAT 2:
A = A + 2
A = A + 9
A = A + 7
REPEAT 9:
A = A + 8
REPEAT 9:
A = A + 8
A = A + 9
A = A + 3
A = A + 2
REPEAT 6:
A = A + 3
REPEAT 9:
A = A + 1
A = A + 9
A = A + 5
REPEAT 2:
A = A + 4
A = A + 9
A = A + 8
REPEAT 5:
A = A + 6
A = A + 9
A = A + 1
REPEAT 1:
A = A + 4
A = A + 2
REPEAT 9:
REPEAT 3:
A = A + 4
REPEAT 7:
A = A + 8
A = A + 3
REPEAT 5:
A = A + 9
REPEAT 8:
A = A + 9
A = A + 8
REPEAT 4:
A = A + 7
A = A + 7
A = A + 3
A = A + 5
REPEAT 6:
A = A + 7
REPEAT 7:
A = A + 2
A = A + 2
A = A + 1
REPEAT 8:
REPEAT 1:
REPEAT 4:
A = A + 6
A = A + 6
A = A + 2
REPEAT 5:
A = A + 4
A = A + 8
A = A + 4
REPEAT 1:
A = A + 5
REPEAT 7:
A = A + 8
REPEAT 6:
A = A + 4
A = A + 4
A = A + 8
REPEAT 4:
A = A + 2
REPEAT 2:
A = A + 4
REPEAT 2:
A = A + 3
REPEAT 1:
A = A + 2
A = A + 8
REPEAT 2:
A = A + 7
REPEAT 8:
A = A + 6
A = A + 1
A = A + 7
REPEAT 8:
A = A + 2
REPEAT 8:
REPEAT 6:
A = A + 1
A = A + 6
REPEAT 2:
A = A + 4
A = A + 1
A = A + 7
A = A + 4
REPEAT 4:
REPEAT 9:
A = A + 2
REPEAT 1:
A = A + 2
A = A + 5
REPEAT 8:
REPEAT 6:
A = A + 3
REPEAT 4:
A = A + 1
A = A + 6
A = A + 1
REPEAT 7:
A = A + 7
REPEAT 7:
A = A + 3
A = A + 9
A = A + 1
A = A + 9
REPEAT 3:
A = A + 5
A = A + 5
A = A + 6
A = A + 2
REPEAT 1:
A = A + 4
REPEAT 2:
A = A + 7
REPEAT 1:
A = A + 7
REPEAT 4:
A = A + 7
A = A + 2
REPEAT 5:
A = A + 9
A = A + 1
A = A + 9
A = A + 5
A = A + 9
REPEAT 5:
A = A + 5
REPEAT 1:
A = A + 6
REPEAT 2:
A = A + 3
A = A + 2
A = A + 6
A = A + 8
A = A + 8
A = A + 7
A = A + 5
A = A + 5
REPEAT 2:
A = A + 1
A = A + 7
A = A + 3
REPEAT 2:
A = A + 7
A = A + 1
A = A + 4
REPEAT 1:
REPEAT 7:
REPEAT 2:
A = A + 3
A = A + 5
A = A + 2
A = A + 6
A = A + 1
A = A + 2
A = A + 4
A = A + 9
REPEAT 1:
A = A + 8
REPEAT 8:
REPEAT 4:
REPEAT 8:
A = A + 4
REPEAT 3:
A = A + 1
A = A + 8
REPEAT 7:
A = A + 8
REPEAT 7:
A = A + 7
A = A + 7
REPEAT 7:
A = A + 6
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 4:
A = A + 5
A = A + 5
A = A + 4
REPEAT 9:
REPEAT 3:
A = A + 4
A = A + 3
A = A + 6
REPEAT 1:
A = A + 3
A = A + 3
A = A + 6
REPEAT 6:
A = A + 7
A = A + 7
A = A + 5
A = A + 5
A = A + 1
A = A + 2
A = A + 6
A = A + 6
REPEAT 9:
A = A + 6
REPEAT 1:
REPEAT 2:
A = A + 4
A = A + 7
REPEAT 3:
A = A + 6
REPEAT 5:
A = A + 3
A = A + 6
REPEAT 9:
A = A + 3
A = A + 6
REPEAT 5:
A = A + 8
A = A + 8
REPEAT 3:
A = A + 7
A = A + 9
A = A + 8
A = A + 3
A = A + 3
A = A + 9
REPEAT 6:
A = A + 9
A = A + 1
REPEAT 4:
REPEAT 1:
A = A + 7
REPEAT 9:
A = A + 2
A = A + 9
A = A + 1
A = A + 2
A = A + 8
A = A + 7
A = A + 9
A = A + 6
REPEAT 4:
REPEAT 2:
A = A + 3
REPEAT 3:
A = A + 4
A = A + 4
REPEAT 6:
A = A + 6
A = A + 1
A = A + 5
A = A + 8
REPEAT 2:
A = A + 6
REPEAT 1:
REPEAT 2:
A = A + 2
REPEAT 3:
A = A + 1
REPEAT 1:
A = A + 8
A = A + 7
A = A + 4
A = A + 2
A = A + 8
A = A + 4
REPEAT 5:
REPEAT 6:
A = A + 8
REPEAT 9:
A = A + 5
A = A + 5
REPEAT 5:
A = A + 5
REPEAT 3:
REPEAT 5:
A = A + 4
REPEAT 4:
A = A + 6
A = A + 3
REPEAT 7:
A = A + 3
A = A + 3
A = A + 1
A = A + 7
A = A + 7
A = A + 6
A = A + 5
A = A + 5
A = A + 6
REPEAT 1:
A = A + 9
A = A + 3
REPEAT 1:
REPEAT 1:
A = A + 1
REPEAT 8:
A = A + 5
REPEAT 8:
A = A + 6
REPEAT 4:
A = A + 9
A = A + 4
REPEAT 2:
A = A + 3
A = A + 7
REPEAT 5:
A = A + 7
A = A + 5
A = A + 8
A = A + 7
A = A + 8
A = A + 5
REPEAT 2:
A = A + 5
A = A + 7
A = A + 8
A = A + 5
A = A + 9
REPEAT 2:
REPEAT 6:
A = A + 9
A = A + 1
A = A + 8
A = A + 7
A = A + 1
A = A + 5
REPEAT 3:
A = A + 3
A = A + 9
A = A + 7
REPEAT 3:
A = A + 9
A = A + 1
REPEAT 6:
A = A + 1
REPEAT 9:
REPEAT 7:
A = A + 3
REPEAT 5:
A = A + 5
A = A + 8
A = A + 8
A = A + 1
A = A + 2
REPEAT 4:
A = A + 6
REPEAT 3:
A = A + 3
A = A + 7
REPEAT 8:
REPEAT 1:
A = A + 7
A = A + 8
A = A + 3
A = A + 1
A = A + 2
A = A + 4
A = A + 7
REPEAT 1:
REPEAT 1:
REPEAT 1:
A = A + 4
A = A + 6
REPEAT 1:
A = A + 3
A = A + 9
A = A + 6
REPEAT 9:
A = A + 1
A = A + 6
REPEAT 5:
A = A + 3
A = A + 9
A = A + 5
A = A + 5
A = A + 7
A = A + 2
REPEAT 2:
A = A + 7
A = A + 7
REPEAT 7:
REPEAT 4:
A = A + 6
A = A + 8
REPEAT 6:
A = A + 6
REPEAT 2:
A = A + 1
A = A + 7
A = A + 6
A = A + 7
REPEAT 4:
REPEAT 7:
A = A + 1
REPEAT 2:
A = A + 2
A = A + 5
A = A + 8
A = A + 2
A = A + 1
A = A + 4
REPEAT 8:
A = A + 5
A = A + 6
REPEAT 7:
REPEAT 6:
REPEAT 9:
A = A + 7
A = A + 8
REPEAT 4:
A = A + 6
A = A + 4
A = A + 3
A = A + 6
REPEAT 9:
A = A + 3
REPEAT 9:
A = A + 2
A = A + 7
A = A + 5
A = A + 2
REPEAT 7:
REPEAT 8:
REPEAT 6:
A = A + 4
A = A + 9
A = A + 5
A = A + 3
A = A + 9
REPEAT 4:
REPEAT 1:
A = A + 6
A = A + 8
REPEAT 1:
A = A + 6
A = A + 4
A = A + 6
REPEAT 3:
A = A + 7
REPEAT 3:
A = A + 4
A = A + 4
A = A + 2
A = A + 3
A = A + 7
REPEAT 5:
A = A + 6
A = A + 5
REPEAT 1:
REPEAT 8:
A = A + 5
REPEAT 3:
A = A + 6
REPEAT 9:
A = A + 4
A = A + 3
REPEAT 6:
REPEAT 2:
A = A + 1
A = A + 5
A = A + 2
A = A + 2
A = A + 7
REPEAT 4:
A = A + 7
A = A + 9
A = A + 2
REPEAT 8:
A = A + 9
REPEAT 9:
REPEAT 2:
A = A + 3
A = A + 2
A = A + 1
A = A + 5
REPEAT 9:
A = A + 1
A = A + 3
A = A + 9
REPEAT 7:
A = A + 2
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 2:
A = A + 4
REPEAT 8:
A = A + 9
REPEAT 5:
A = A + 5
A = A + 4
A = A + 2
A = A + 4
REPEAT 6:
A = A + 2
REPEAT 5:
A = A + 7
A = A + 7
A = A + 8
A = A + 3
REPEAT 8:
A = A + 2
A = A + 5
REPEAT 1:
A = A + 8
A = A + 5
A = A + 1
A = A + 1
A = A + 5
REPEAT 2:
A = A + 6
REPEAT 6:
A = A + 9
A = A + 2
A = A + 5
REPEAT 4:
A = A + 7
A = A + 1
REPEAT 6:
A = A + 8
A = A + 4
REPEAT 3:
REPEAT 2:
A = A + 1
A = A + 5
REPEAT 2:
A = A + 7
REPEAT 9:
A = A + 6
A = A + 8
A = A + 9
A = A + 5
REPEAT 9:
REPEAT 3:
A = A + 7
A = A + 7
A = A + 9
A = A + 7
REPEAT 5:
A = A + 7
A = A + 2
A = A + 1
A = A + 8
A = A + 3
A = A + 5
A = A + 1
REPEAT 8:
A = A + 4
A = A + 2
A = A + 2
A = A + 8
REPEAT 4:
REPEAT 4:
A = A + 8
REPEAT 7:
A = A + 5
A = A + 2
REPEAT 2:
A = A + 6
REPEAT 4:
A = A + 8
A = A + 6
A = A + 1
A = A + 3
A = A + 2
A = A + 7
A = A + 4
REPEAT 8:
A = A + 2
A = A + 4
REPEAT 5:
REPEAT 3:
REPEAT 6:
A = A + 8
A = A + 1
A = A + 6
A = A + 5
A = A + 9
REPEAT 8:
A = A + 7
REPEAT 6:
A = A + 4
A = A + 5
REPEAT 3:
A = A + 1
REPEAT 1:
REPEAT 5:
A = A + 6
A = A + 2
REPEAT 9:
REPEAT 5:
A = A + 9
A = A + 3
REPEAT 9:
A = A + 9
A = A + 8
REPEAT 8:
REPEAT 5:
A = A + 9
A = A + 4
REPEAT 9:
A = A + 3
A = A + 4
A = A + 5
REPEAT 9:
REPEAT 7:
A = A + 5
REPEAT 3:
A = A + 7
REPEAT 9:
REPEAT 6:
A = A + 4
A = A + 6
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 3
A = A + 3
A = A + 3
A = A + 5
REPEAT 7:
A = A + 5
REPEAT 2:
A = A + 5
A = A + 6
REPEAT 2:
A = A + 2
A = A + 5
A = A + 3
A = A + 5
A = A + 5
REPEAT 4:
A = A + 2
A = A + 1
REPEAT 9:
A = A + 9
A = A + 5
A = A + 6
A = A + 2
A = A + 2
A = A + 5
REPEAT 9:
A = A + 5
A = A + 4
REPEAT 4:
REPEAT 4:
A = A + 1
A = A + 2
REPEAT 6:
A = A + 9
A = A + 3
REPEAT 2:
A = A + 5
A = A + 1
A = A + 1
A = A + 3
A = A + 8
REPEAT 7:
A = A + 4
REPEAT 6:
A = A + 9
REPEAT 5:
A = A + 9
A = A + 8
A = A + 3
A = A + 9
A = A + 4
A = A + 6
REPEAT 7:
A = A + 9
REPEAT 9:
A = A + 4
A = A + 9
A = A + 1
A = A + 3
REPEAT 5:
REPEAT 1:
A = A + 4
A = A + 4
REPEAT 8:
A = A + 9
A = A + 6
A = A + 2
REPEAT 3:
A = A + 4
A = A + 4
REPEAT 3:
A = A + 5
A = A + 2
A = A + 8
A = A + 3
A = A + 6
A = A + 4
A = A + 9
A = A + 1
A = A + 9
A = A + 5
A = A + 3
REPEAT 3:
A = A + 2
A = A + 5
A = A + 8
A = A + 2
A = A + 5
REPEAT 8:
REPEAT 2:
A = A + 6
A = A + 7
A = A + 6
A = A + 9
A = A + 2
REPEAT 2:
A = A + 3
REPEAT 8:
A = A + 7
A = A + 2
A = A + 1
A = A + 4
A = A + 1
A = A + 5
A = A + 2
A = A + 1
REPEAT 1:
A = A + 1
REPEAT 6:
A = A + 4
A = A + 3
A = A + 3
REPEAT 5:
A = A + 3
REPEAT 6:
REPEAT 1:
A = A + 5
A = A + 7
A = A + 7
A = A + 7
REPEAT 5:
A = A + 9
A = A + 7
REPEAT 5:
A = A + 9
A = A + 1
A = A + 9
A = A + 8
REPEAT 1:
A = A + 2
REPEAT 5:
A = A + 8
REPEAT 3:
A = A + 2
A = A + 9
A = A + 6
A = A + 3
REPEAT 5:
REPEAT 6:
A = A + 5
A = A + 5
REPEAT 4:
A = A + 5
A = A + 4
REPEAT 8:
A = A + 9
A = A + 1
REPEAT 8:
A = A + 8
A = A + 1
A = A + 4
REPEAT 6:
A = A + 6
REPEAT 2:
A = A + 3
A = A + 9
A = A + 6
A = A + 9
REPEAT 1:
A = A + 4
REPEAT 3:
A = A + 3
A = A + 4
A = A + 2
A = A + 8
REPEAT 2:
A = A + 4
A = A + 1
REPEAT 9:
A = A + 2
A = A + 9
A = A + 7
REPEAT 7:
REPEAT 7:
REPEAT 5:
A = A + 7
REPEAT 5:
A = A + 1
A = A + 1
REPEAT 5:
A = A + 6
REPEAT 1:
A = A + 4
REPEAT 9:
A = A + 4
A = A + 1
REPEAT 6:
A = A + 8
A = A + 5
REPEAT 1:
A = A + 4
REPEAT 5:
A = A + 8
A = A + 7
A = A + 2
REPEAT 3:
A = A + 3
REPEAT 8:
REPEAT 8:
A = A + 4
A = A + 7
REPEAT 5:
A = A + 1
REPEAT 8:
A = A + 7
A = A + 8
A = A + 4
A = A + 7
A = A + 6
A = A + 9
A = A + 5
REPEAT 3:
A = A + 5
REPEAT 9:
A = A + 1
A = A + 7
REPEAT 1:
A = A + 8
A = A + 4
REPEAT 8:
REPEAT 7:
A = A + 2
REPEAT 4:
A = A + 6
A = A + 6
REPEAT 1:
A = A + 7
A = A + 1
REPEAT 9:
REPEAT 5:
A = A + 6
A = A + 5
REPEAT 7:
A = A + 3
A = A + 6
A = A + 8
REPEAT 2:
A = A + 7
A = A + 1
A = A + 9
REPEAT 3:
REPEAT 3:
A = A + 5
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
char mp[N][N];
int s[N], t[N], top;
int main()
{
FILE *fp;
fp = fopen("prog.txt", "r"); ///文件读操作
char ch;
int tot = 0;
int i = 0;
while ((ch = fgetc(fp)) != EOF) ///一个字符一个字符的读入
{
if (ch == '\n')
{
mp[tot][i] = '\0';
tot++;
i = 0;
continue;
}
mp[tot][i++] = ch;
}
/*
for(int i=0;i<tot;i++)
printf("%s\n",mp[i]);*/
///将txt中的数据已经全部保存在了mp数组中
top = 0;
int p, w = 1, sum = 0;
s[top] = -1, t[top] = -1; ///防止栈空的时候进行出栈操作
for (int i = 0; i < tot; i++)
{
int len = strlen(mp[i]);
p = 0;
while (mp[i][p] == ' ') ///统计缩进
p++;
while (s[top] >= p) ///开始新的循环,上一层的循环不包括
w /= t[top--];
if (mp[i][len - 1] == ':') ///当前是循环语句
{
int num = mp[i][len - 2] - '0';
top++;
w *= num; ///累计循环了几次
s[top] = p, t[top] = num; ///第top层循环语句的缩进量和循环次数
}
else
{
int num = mp[i][len - 1] - '0';
sum += w * num;
}
}
printf("%d\n", sum);
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
RSA是一种经典的加密算法。它的基本加密过程如下。
首先生成两个质数p,q, 令$n = p \cdot q$,设d与$(p-1) \cdot (q-1)$互质,则可以找到e,使得$d \cdot e$除以$(p-1) \cdot (q-1)$的余数为1
n,d,e组成了私钥,n,d构成了公钥。
当使用公钥加密一个整数X时(X<=n-1),计算$C = X^d$ mod n,则C是加密后的密文。
当收到密文C时,可以使用私钥解开,计算公式为:$X = C^e$ mod n。
例如:当p = 5, q = 11, n = 55, e = 27。
若加密数字24,得$24^3$ % 55 = 19。
解密数字19,得$19^{27}$ % 55 = 24。
现在你知道公钥中n = 1001733993063167141,d = 212353,同时,你截获了别人发送的密文C = 20190324,请问,原文是多少?
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e8 + 10;
const LL n = 1001733993063167141ll;
const LL p = 891234941ll;
const LL q = 1123984201ll;
const LL d = 212353;
const LL c = 20190324;
int a[maxn];
int sushu[maxn / 10];
bool notPrime[maxn]; ///筛素数分解不出来,目测是9位数*10位数
int cnt;
void getPrime(int n)
{
for (int i = 2; i <= n; ++i)
{
if (!notPrime[i])
sushu[cnt++] = i;
for (int j = 0; j < cnt && 1ll * i * sushu[j] <= n; ++j)
{
notPrime[i * sushu[j]] = true;
if (i % sushu[j] == 0)
break;
}
}
for (int i = 0; i < 20; ++i)
cout << sushu[i] << " ";
cout << endl;
}
void fenjie(LL x)
{
cout << x << " = 1";
for (int i = 0; i < cnt && sushu[i] <= x / sushu[i]; ++i)
{
while (x % sushu[i] == 0)
{
cout << " * " << sushu[i];
x /= sushu[i];
}
}
if (x > 1)
cout << " * " << x;
cout << endl;
}
void BF(LL x)
{
cout << x << " = ";
for (LL i = 1e8 + 1; i < x; i += 2)
{
if (x % i == 0)
cout << i << " * ", x /= i;
}
cout << x << endl;
}
void exgcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
return;
}
exgcd(b, a % b, d, y, x);
y -= (a / b) * x;
}
LL rev(LL t, LL m)
{
LL d, x, y;
exgcd(t, m, d, x, y);
return (x % m + m) % m;
}
LL fast_product(LL a, LL b, LL mod)
{
LL ans = 0;
while (b)
{
if (b & 1)
ans = (ans + a) % mod;
a = (a + a) % mod;
b >>= 1;
}
return ans;
}
LL fast_pow(LL a, LL b, LL mod)
{
LL ans = 1;
while (b)
{
if (b & 1)
ans = fast_product(ans, a, mod);
a = fast_product(a, a, mod);
b >>= 1;
}
return ans;
}
int main()
{
//getPrime(maxn-5);
//fenjie(n);
BF(n);
LL y = (p - 1) * (q - 1);
LL e = rev(d, y);
LL answer = fast_pow(c, e, n);
cout << answer << endl;
return 0;
}
{
"node_id": "opencv-5437ea08671b4d9c888ad064723cce4d",
"keywords": [],
"title": "蓝桥杯"
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
给定一个长度为N的数列,$A_1, A_2, … A_N,$如果其中一段连续的子序列$A_i, A_{i+1}, … A_j(i <= j)$之和是K的倍数,我们就称这个区间[i, j]是K倍区间。
你能求出数列中总共有多少个K倍区间吗?
#### 输入格式
第一行包含两个整数N和K。(1 <= N, K <= 100000)
以下N行每行包含一个整数$A_i$。(1 <= $A_i$ <= 100000)
#### 输出格式
输出一个整数,代表K倍区间的数目。
#### 样例输入
```
5 2
1
2
3
4
5
```
#### 样例输出
```
6
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, k, ans = 0, son[100000], sum[100000], b[100000] = {0};
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> son[i];
if (i != 0)
sum[i] = (sum[i - 1] + son[i]) % k;
else
sum[i] = son[i] % k;
b[sum[i]]++;
ans += b[sum[i]] - 1;
if (sum[i] == 0)
ans++;
}
cout << ans;
return 0;
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
#### 题目描述
三体人将对地球发起攻击。为了抵御攻击,地球人派出了 A × B × C 艘战舰,在太空中排成一个 A 层 B 行 C 列的立方体。其中,第 i 层第 j 行第 k 列的战舰(记为战舰 (i, j, k))的生命值为 d(i, j, k)。
三体人将会对地球发起 m 轮“立方体攻击”,每次攻击会对一个小立方体中的所有战舰都造成相同的伤害。具体地,第 t 轮攻击用 7 个参数 $la_t, ra_t, lb_t, rb_t, lc_t, rc_t, h_t $描述;
所有满足$ i ∈ [la_t, ra_t],j ∈ [lb_t, rb_t],k ∈ [lc_t, rc_t] $的战舰 (i, j, k) 会受到 $h_t$ 的伤害。如果一个战舰累计受到的总伤害超过其防御力,那么这个战舰会爆炸。
地球指挥官希望你能告诉他,第一艘爆炸的战舰是在哪一轮攻击后爆炸的。
#### 输入格式
从标准输入读入数据。
第一行包括 4 个正整数 A, B, C, m;
第二行包含 A × B × C 个整数,其中第 ((i − 1)×B + (j − 1)) × C + (k − 1)+1 个数为 d(i, j, k);
第 3 到第 m + 2 行中,第 (t − 2) 行包含 7 个正整数 $la_t, ra_t, lb_t, rb_t, lc_t, rc_t, h_t$。
#### 输出格式
输出到标准输出。
输出第一个爆炸的战舰是在哪一轮攻击后爆炸的。保证一定存在这样的战舰。
#### 样例输入
```
2 2 2 3
1 1 1 1 1 1 1 1
1 2 1 2 1 1 1
1 1 1 2 1 2 1
1 1 1 1 1 1 2
```
#### 样例输出
```
2
```
#### 样例解释
在第 2 轮攻击后,战舰 (1,1,1) 总共受到了 2 点伤害,超出其防御力导致爆炸。
#### 数据约定
```
对于 10% 的数据,B = C = 1;
对于 20% 的数据,C = 1;
对于 40% 的数据,A × B × C, m ≤ 10, 000;
对于 70% 的数据,A, B, C ≤ 200;
对于所有数据,A × B × C ≤ 10^6, m ≤ 10^6, 0 ≤ d(i, j, k), ht ≤ 10^9。
```
\ No newline at end of file
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2000010;
typedef long long LL;
int A, B, C, m;
LL s[N], b[N], bp[N];
int op[N / 2][7];
const int d[8][4] = {
{0, 0, 0, 1},
{0, 0, 1, -1},
{0, 1, 0, -1},
{0, 1, 1, 1},
{1, 0, 0, -1},
{1, 0, 1, 1},
{1, 1, 0, 1},
{1, 1, 1, -1}};
int get(int i, int j, int k)
{
return (i * B + j) * C + k;
}
bool check(int mid)
{
memcpy(b, bp, sizeof bp);
for (int i = 1; i <= mid; i++)
{
int x1 = op[i][0], x2 = op[i][1], y1 = op[i][2], y2 = op[i][3], z1 = op[i][4], z2 = op[i][5], h = op[i][6];
b[get(x1, y1, z1)] -= h;
b[get(x1, y1, z2 + 1)] += h;
b[get(x1, y2 + 1, z1)] += h;
b[get(x1, y2 + 1, z2 + 1)] -= h;
b[get(x2 + 1, y1, z1)] += h;
b[get(x2 + 1, y1, z2 + 1)] -= h;
b[get(x2 + 1, y2 + 1, z1)] -= h;
b[get(x2 + 1, y2 + 1, z2 + 1)] += h;
}
memset(s, 0, sizeof s);
for (int i = 1; i <= A; i++)
for (int j = 1; j <= B; j++)
for (int k = 1; k <= C; k++)
{
s[get(i, j, k)] = b[get(i, j, k)];
for (int u = 1; u < 8; u++)
{
int x = i - d[u][0], y = j - d[u][1], z = k - d[u][2], t = d[u][3];
s[get(i, j, k)] -= s[get(x, y, z)] * t;
}
if (s[get(i, j, k)] < 0)
return true;
}
return false;
}
int main()
{
scanf("%d%d%d%d", &A, &B, &C, &m);
for (int i = 1; i <= A; i++)
for (int j = 1; j <= B; j++)
for (int k = 1; k <= C; k++)
scanf("%lld", &s[get(i, j, k)]);
for (int i = 1; i <= A; i++)
for (int j = 1; j <= B; j++)
for (int k = 1; k <= C; k++)
for (int u = 0; u < 8; u++)
{
int x = i - d[u][0], y = j - d[u][1], z = k - d[u][2], t = d[u][3];
bp[get(i, j, k)] += s[get(x, y, z)] * t;
}
for (int i = 1; i <= m; i++)
for (int j = 0; j < 7; j++)
scanf("%d", &op[i][j]);
int l = 1, r = m;
while (l < r)
{
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", r);
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
观察下面的加法算式:
![](https://img-blog.csdnimg.cn/20200323231451860.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzkxMDMyMA==,size_16,color_FFFFFF,t_70#pic_center)
其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。
请你填写“三羊献瑞”所代表的4位数字(答案唯一)
\ No newline at end of file
#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int main()
{
for (int i = 0; i < 10; i++)
a[i] = i;
do
{
if (!a[0] || !a[4])
continue; //祥、三不能为0
int t1 = a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3]; //祥瑞生辉
int t2 = a[4] * 1000 + a[5] * 100 + a[6] * 10 + a[1]; //三羊献瑞
int t3 = a[4] * 10000 + a[5] * 1000 + a[2] * 100 + a[1] * 10 + a[7]; //三羊生瑞气
if (t1 + t2 == t3)
{
cout << t2;
break;
}
} while (next_permutation(a, a + 10));
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
已知三角形三个顶点在直角坐标系下的坐标分别为:
```
(2.3,2.5)
(6.4,3.1)
(5.1,7.2)
```
求该三角形的面积。
\ No newline at end of file
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef pair<double, double> PDD;
#define x first
#define y second
double cross(double x1, double y1, double x2, double y2)
{
return x1 * y2 - x2 * y1;
}
int main()
{
PDD pts[3];
for (int i = 0; i < 3; i++)
{
scanf("%lf%lf", &pts[i].first, &pts[i].second);
}
cout << 0.5 * cross(pts[1].x - pts[0].x, pts[1].y - pts[0].y, pts[2].x - pts[0].x, pts[2].y - pts[0].y) << endl;
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
一般的排序有许多经典算法,如快速排序、希尔排序等。但实际应用时,经常会或多或少有一些特殊的要求。我们没必要套用那些经典算法,可以根据实际情况建立更好的解法。
比如,对一个整型数组中的数字进行分类排序:
使得负数都靠左端,正数都靠右端,0在中部。注意问题的特点是:负数区域和正数区域内并不要求有序。可以利用这个特点通过1次线性扫描就结束战斗!!
以下的程序实现了该目标。
其中x指向待排序的整型数组,len是数组的长度。
#include <iostream>
using namespace std;
void sort3p(int *x, int len)
{
int p = 0;
int left = 0;
int right = len - 1;
while (p <= right)
{
if (x[p] < 0)
{
int t = x[left];
x[left] = x[p];
x[p] = t;
left++;
p++;
}
else if (x[p] > 0)
{
int t = x[right];
x[right] = x[p];
x[p] = t;
right--;
}
else
{
p++; //填空位置
}
}
}
int main()
{
int a[10] = {0, -1, 0, 0, -2, 5, 3, 1, 0, 7};
sort3p(a, 10);
for (int i = 0; i < 10; i++)
{
printf("%d ", a[i]);
}
return 0;
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"蓝桥杯",
"不同子串"
],
"children": [],
"export": [
"solution.json"
],
"title": "不同子串"
}
\ No newline at end of file
#### 题目描述
一个字符串的非空子串是指字符串中长度至少为1 的连续的一段字符组成的串。
例如,字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab,一共7 个。
注意在计算时,只算本质不同的串的个数。
请问,字符串```0100110001010001```有多少个不同的非空子串?
#include <bits/stdc++.h>
using namespace std;
int main()
{
set<string> s;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++)
for (int j = i; j < str.size(); j++)
s.insert(str.substr(i, j - i + 1));
cout << s.size();
return 0;
}
\ No newline at end of file
public class Demo2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
sc.close();
Set<String> set = new HashSet<String>();
for (int i = 0; i < str.length() + 1; i++) {
for (int j = i + 1; j < str.length() + 1; j++) {
set.add(str.substring(i, j));
}
}
System.out.println(set.size());
}
}
{
"type": "code_options",
"author": "CSDN.net",
"source": "solution.md",
"exercise_id": "f082ace1da0e4cc49ae265c6860b4cbc"
}
\ No newline at end of file
# 不同子串
#### 题目描述
一个字符串的非空子串是指字符串中长度至少为1 的连续的一段字符组成的串。
例如,字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab,一共7 个。
注意在计算时,只算本质不同的串的个数。
请问,字符串```0100110001010001```有多少个不同的非空子串?
## aop
### before
```cpp
#include <bits/stdc++.h>
using namespace std;
```
### after
```cpp
```
## 答案
```cpp
int main()
{
set<string> s;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++)
for (int j = i; j < str.size(); j++)
s.insert(str.substr(i, j - i + 1));
cout << s.size();
return 0;
}
```
## 选项
### A
```cpp
int main()
{
set<string> s;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++)
for (int j = i; j < str.size(); j++)
s.insert(str.substr(i, j + i - 1));
cout << s.size();
return 0;
}
```
### B
```cpp
int main()
{
set<string> s;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++)
for (int j = i; j < str.size(); j++)
s.insert(str.substr(i, j + 1));
cout << s.size();
return 0;
}
```
### C
```cpp
int main()
{
set<string> s;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++)
for (int j = i; j < str.size(); j++)
s.insert(str.substr(i, j - i));
cout << s.size();
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
曾有邪教称1999年12月31日是世界末日。当然该谣言已经不攻自破。
还有人称今后的某个世纪末的12月31日,如果是星期一则会....
有趣的是,任何一个世纪末的年份的12月31日都不可能是星期一!!
于是,“谣言制造商”又修改为星期日......
1999年的12月31日是星期五,请问:未来哪一个离我们最近的一个世纪末年(即xx99年)的12月31日正好是星期天(即星期日)?
请回答该年份(只写这个4位整数,不要写12月31等多余信息)
#include <iostream>
using namespace std;
int main()
{
long long sum = 0;
for (int i = 2000;; i++)
{
sum += (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) ? 366 : 365;
if (i % 100 == 99 && sum % 7 == 2)
{
cout << i << endl;
break;
}
}
return 0;
}
\ No newline at end of file
{
"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": []
}
\ No newline at end of file
1~9的数字可以组成3个3位数,设为:A,B,C, 现在要求满足如下关系:
```
B = 2 * A
C = 3 * A
```
请你写出A的所有可能答案,数字间用空格分开,数字按升序排列。
\ No newline at end of file
public class Test004 {
public static void main(String[] args) {
for (int a = 111; a <= 333; a++) {
if (hasZero(a)) {
continue;
} else {
int b = 2 * a;
int c = 3 * a;
if (hasZero(b) || hasZero(c)) {
continue;
}
String s = "" + a + b + c;
if (isFind(s)) {
System.out.print(a + " ");
}
}
}
}
private static boolean hasZero(int n) {
return String.valueOf(n).contains("0");
}
private static boolean isFind(String x) {
char[] arr = x.toCharArray();
Arrays.sort(arr);
return "123456789".equals(String.valueOf(arr));
}
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
1,2,3…9 这九个数字组成一个分数,其值恰好为1/3,如何组法?
\ No newline at end of file
// 九数组分数
#include <stdio.h>
void test(int x[])
{
int a = x[0] * 1000 + x[1] * 100 + x[2] * 10 + x[3];
int b = x[4] * 10000 + x[5] * 1000 + x[6] * 100 + x[7] * 10 + x[8];
if (a * 3 == b)
printf("%d / %d\n", a, b);
}
void f(int x[], int k)
{
int i, t;
if (k >= 9)
{
test(x);
return;
}
for (i = k; i < 9; i++)
{
{
t = x[k];
x[k] = x[i];
x[i] = t;
}
f(x, k + 1);
{
t = x[i];
x[i] = x[k];
x[k] = t;
}
}
}
int main()
{
int x[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
f(x, 0);
return 0;
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
2004年起,国际ISBN中心出版了《13位国际标准书号指南》。
原有10位书号前加978作为商品分类标识;校验规则也改变。
校验位的加权算法与10位ISBN的算法不同,具体算法是:
1. 用1分别乘ISBN的前12位中的奇数位(从左边开始数起),用3乘以偶数位,乘积之和以10为模,
2. 10与模值的差值再对10取模(即取个位的数字)即可得到校验位的值,其值范围应该为0~9。
下面的程序实现了该算法,请仔细阅读源码,填写缺失的部分。
#include <stdio.h>
// 验证成功返回 1,否则返回 0
int f(const char *s)
{
int k = 1;
int sum = 0;
int i;
for (i = 0; s[i] != '\0'; i++)
{
char c = s[i];
if (c == '-' || c == ' ')
continue;
sum += k % 2 == 1 ? (c - '0') * 3 : (c - '0');
k++;
if (k > 12)
break;
}
while (s[i] != '\0')
i++;
return (s[i - 1] - '0') == (10 - sum % 10) % 10;
}
int main()
{
printf("%d\n", f("978-7-301-04815-3"));
printf("%d\n", f("978-7-115-38821-6"));
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
小明开了一家糖果店。他别出心裁:把水果糖包成4颗一包和7颗一包的两种。糖果不能拆包卖。
小朋友来买糖的时候,他就用这两种包装来组合。当然有些糖果数目是无法组合出来的,比如要买 10 颗糖。
你可以用计算机测试一下,在这种包装情况下,最大不能买到的数量是17。大于17的任何数字都可以用4和7组合出来。
本题的要求就是在已知两个包装的数量时,求最大不能组合出的数字。
#### 输入格式
两个正整数,表示每种包装中糖的颗数(都不多于1000)
#### 输出格式
一个正整数,表示最大不能买到的糖数
#### 样例输入1
```
4 7
```
#### 样例输出1
```
17
```
#### 样例输入2
```
3 5
```
#### 样例输出2
```
7
```
\ No newline at end of file
#include <stdio.h>
bool b[100000];
int min(int a, int b)
{
if (a < b)
{
return a;
}
else
{
return b;
}
}
int main()
{
int n, m, j = 0, max = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i <= m; i++)
for (int j = 0; j <= n; j++)
{
if (i * n + j * m >= 100000)
break;
b[i * n + j * m] = true;
}
for (int i = min(m, n); i <= n * m; i++)
{
if (b[i])
{
j++;
if (j == min(m, n))
{
printf("%d", max);
break;
}
}
else
{
max = i;
j = 0;
}
}
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
有N个瓶子,编号 1 ~ N,放在架子上。
比如有5个瓶子:
2 1 3 5 4
要求每次拿起2个瓶子,交换它们的位置。
经过若干次后,使得瓶子的序号为:
1 2 3 4 5
对于这么简单的情况,显然,至少需要交换2次就可以复位。
如果瓶子更多呢?你可以通过编程来解决。
输入格式为两行:
第一行: 一个正整数N(N<10000), 表示瓶子的数目
第二行:N个正整数,用空格分开,表示瓶子目前的排列情况。
输出数据为一行一个正整数,表示至少交换多少次,才能完成排序。
例如,输入:
```
5
3 1 2 5 4
```
程序应该输出:
```
3
```
再例如,输入:
```
5
5 4 3 2 1
```
程序应该输出:
```
2
```
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e4 + 10;
bool st[N];
int a[N], n, k;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i]; //瓶子初始序号
for (int i = 1; i <= n; i++) //从每个正确序号出发
if (!st[i]) //如果没有走过
{
k++; //环数量加一
for (int j = i; !st[j]; j = a[j]) //走完这个环 每次变更指向a[j] 即瓶子初始序号的第j个
st[j] = true;
}
cout << n - k; //环最简情况为自指 则最多有n个环 当前有k个环 从K达到n则需要n-k次
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
小明正在分析一本小说中的人物相关性。
他想知道在小说中 Alice 和 Bob 有多少次同时出现。
更准确的说,小明定义 Alice 和 Bob “同时出现”的意思是:在小说文本中 Alice 和 Bob 之间不超过 K 个字符。
例如以下文本:
```
This is a story about Alice and Bob. Alice wants to send a private message to Bob.
```
假设 K=20,则 Alice 和 Bob 同时出现了 2 次,分别是 Alice and Bob 和 Bob. Alice。
前者 Alice 和 Bob 之间有 5 个字符,后者有 2 个字符。
注意:
1. Alice 和 Bob 是大小写敏感的,alice 或 bob 等并不计算在内。
2. Alice 和 Bob 应为单独的单词,前后可以有标点符号和空格,但是不能有字母。例如 Bobbi 並不算出现了 Bob。
#### 输入格式
第一行包含一个整数 K。
第二行包含一行字符串,只包含大小写字母、标点符号和空格。长度不超过 1000000。
#### 输出格式
输出一个整数,表示 Alice 和 Bob 同时出现的次数。
#### 数据范围
```
1≤K≤1000000
```
#### 输入样例:
```
20
This is a story about Alice and Bob. Alice wants to send a private message to Bob.
```
输出样例:
```
2
```
\ No newline at end of file
#include <bits/stdc++.h>
using namespace std;
int len;
string s;
bool check(int i)
{
if (len - i < 5)
return false;
return s[i + 1] == 'l' && s[i + 2] == 'i' && s[i + 3] == 'c' && s[i + 4] == 'e';
}
bool check2(int i)
{
if (len - i < 3)
return false;
return s[i + 1] == 'o' && s[i + 2] == 'b';
}
int main()
{
int k; //这里绝对不能加关闭流读入,如果这加了getline会直接读不到
cin >> k;
getchar();
getline(cin, s);
len = s.length();
vector<int> Alice, Bob;
for (int i = 0; i < len; i++)
{
if (s[i] == 'A' && check(i))
{
Alice.push_back(i);
i += 5;
}
else if (s[i] == 'B' && check2(i))
{
Bob.push_back(i);
i += 3;
}
}
int As = Alice.size(), Bs = Bob.size();
int i = 0, j = 0;
long long ans = 0;
for (int q = 0; q < As; q++)
{
while (i < Bs && Bob[i] < Alice[q] - k - 3)
i++; //左边界已经有些被排除的
while (j < Bs && Bob[j] <= Alice[q] + k + 5)
j++; //右边界
ans += j - i;
}
cout << ans << "\n";
return 0;
}
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
#### 题目描述
几个人一起出去吃饭是常有的事。但在结帐的时候,常常会出现一些争执。
现在有 n 个人出去吃饭,他们总共消费了 S 元。其中第 i 个人带了 ai 元。幸运的是,所有人带的钱的总数是足够付账的,但现在问题来了:每个人分别要出多少钱呢?
为了公平起见,我们希望在总付钱量恰好为 S 的前提下,最后每个人付的钱的标准差最小。这里我们约定,每个人支付的钱数可以是任意非负实数,即可以不是1分钱的整数倍。你需要输出最小的标准差是多少。
标准差的介绍:标准差是多个数与它们平均数差值的平方平均数,一般用于刻画这些数之间的“偏差有多大”。形式化地说,设第 i 个人付的钱为 bi 元,那么标准差为 :
![参见p1.png](https://img-blog.csdnimg.cn/20201015164915888.png#pic_center)
#### 输入格式
从标准输入读入数据。
第一行包含两个整数 n、S;
第二行包含 n 个非负整数 a1, …, an。
#### 输出格式
输出到标准输出。
输出最小的标准差,四舍五入保留 4 位小数。
保证正确答案在加上或减去 10^−9 后不会导致四舍五入的结果发生变化。
#### 样例1输入
```
5 2333
666 666 666 666 666
```
#### 样例输出
```
0.0000
```
#### 样例解释
每个人都出 2333/5 元,标准差为 0。
#### 样例输入
```
10 30
2 1 4 7 4 8 3 6 4 7
```
#### 样例输出
```
0.7928
```
#### 数据说明
对于 10% 的数据,所有 ai 相等;
对于 30% 的数据,所有非 0 的 ai 相等;
对于 60% 的数据,n ≤ 1000;
对于 80% 的数据,n ≤ 10^5;
对于所有数据,n ≤ 5 × 10^5, 0 ≤ ai ≤ 10^9。
#### 资源约定:
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int num_of_people; //人数
int total_money; //总需要付款
int each_afford[500001]; //每个人余款
cin >> num_of_people;
cin >> total_money;
for (int i = 0; i < num_of_people; i++)
{
cin >> each_afford[i];
}
sort(each_afford, each_afford + num_of_people); //将每个人余款升序排序
double avg = total_money * 1.0 / num_of_people; //计算初始平摊要给的钱
double newavg = avg; //新的平均值
double ans = 0; //方差
for (int i = 0; i < num_of_people; i++)
{
if (each_afford[i] < newavg) //有的人连AA都给不起,让他们把现有的钱全给了
{
ans = ans + pow((each_afford[i] - avg), 2); //此时的方差
total_money = total_money - each_afford[i]; //减掉给不起平摊的人的所有余款
newavg = total_money * 1.0 / (num_of_people - i - 1); //减掉给不起平摊的钱之后算的平均值
}
else
{
ans += (num_of_people - i) * pow(newavg - avg, 2);
break;
}
}
ans = sqrt(ans / num_of_people);
printf("%.4lf\n", ans);
return 0;
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [],
"export": []
}
\ No newline at end of file
#### 问题描述
给定一个长度为 N 的数组$ A = [A_1; A_2; · · · A_N]$,数组中有可能有重复出现的整数。
现在小明要按以下方法将其修改为没有重复整数的数组。小明会依次修改$A_2, A_3, · · · , A_N$。
当修改 $A_i$时,小明会检查 $A_i$ 是否在$ A_1 ∼ A_{i−1} $中出现过。如果出现过,则小明会给$ A_i $加上 1 ;如果新的$ A_i $仍在之前出现过,小明会持续给$ A_i $加 1 ,直到$ A_i $没有在$ A_1 ∼ A_{i−1}$ 中出现过。
当$ A_N $也经过上述修改之后,显然 A 数组中就没有重复的整数了。
现在给定初始的 A 数组,请你计算出最终的 A 数组。
#### 输入格式
第一行包含一个整数 N。
第二行包含 N 个整数$ A_1; A_2; · · · ; A_N $。
#### 输出格式
输出 N 个整数,依次是最终的$ A_1; A_2; · · · ; A_N $。
#### 样例输入
```
5
2 1 1 3 4
```
#### 样例输出
```
2 1 3 4 5
```
#include <iostream>
using namespace std;
const int N = 1000010;
int a[N];
int find(int x)
{
if (a[x] != x)
a[x] = find(a[x]);
return a[x];
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= N; i++)
a[i] = i;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
x = find(x);
cout << a[x] << " ";
a[x] = x + 1;
}
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": []
}
\ No newline at end of file
你有一张某海域 N×N 像素的照片,”.”表示海洋、”#”表示陆地,如下所示:
```
.......
.##....
.##....
....##.
..####.
...###.
.......
```
其中”上下左右”四个方向上连在一起的一片陆地组成一座岛屿,例如上图就有 2 座岛屿。
由于全球变暖导致了海面上升,科学家预测未来几十年,岛屿边缘一个像素的范围会被海水淹没。
具体来说如果一块陆地像素与海洋相邻(上下左右四个相邻像素中有海洋),它就会被淹没。
例如上图中的海域未来会变成如下样子:
```
.......
.......
.......
.......
....#..
.......
.......
```
请你计算:依照科学家的预测,照片中有多少岛屿会被完全淹没。
#### 输入格式
第一行包含一个整数N。
以下 N 行 N 列,包含一个由字符”#”和”.”构成的 N×N 字符矩阵,代表一张海域照片,”#”表示陆地,”.”表示海洋。
照片保证第 1 行、第 1 列、第 N 行、第 N 列的像素都是海洋。
#### 输出格式
一个整数表示答案。
#### 数据范围
```
1≤N≤1000
```
#### 输入样例1:
```
7
.......
.##....
.##....
....##.
..####.
...###.
.......
```
#### 输出样例1:
```
1
```
#### 输入样例2:
```
9
.........
.##.##...
.#####...
.##.##...
.........
.##.#....
.#.###...
.#..#....
.........
```
#### 输出样例2:
```
1
```
#include <iostream>
#include <queue>
using namespace std;
int n;
const int N = 1e3 + 10;
char g[N][N];
bool st[N][N]; //状态 判断是否走过
typedef pair<int, int> PII; //需要长款两个变量定位
#define x first
#define y second
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; //移动的偏移量
void bfs(int x, int y, int &sum, int &bound) //土地量与淹没量,后续需要使用 所以&
{
st[x][y] = true;
queue<PII> q;
q.push({x, y});
while (q.size()) //BFS必然遍历完整个岛屿
{
auto t = q.front();
q.pop();
bool is_bound = false;
sum++;
for (int i = 0; i < 4; i++)
{
int tmpx = t.x + dx[i], tmpy = t.y + dy[i];
if (tmpx < 0 || tmpx >= n || tmpy < 0 || tmpy >= n)
continue; //边界
else if (st[tmpx][tmpy])
continue; //走过
else if (g[tmpx][tmpy] == '.') //说明上一个地点临海
{
is_bound = true;
continue;
}
st[tmpx][tmpy] = true;
q.push({tmpx, tmpy});
}
if (is_bound)
bound++; //四个方向有一个临海 则该地区沉没
}
return;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> g[i]; //读入地图
int cnt = 0; //未被完全淹没的岛屿数量
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (g[i][j] == '#' && !st[i][j]) //当遍历到土地 且 未走过时 遍历能走到的整个岛屿
{
int sum = 0, bound = 0;
bfs(i, j, sum, bound);
if (sum == bound)
cnt++; //沉没量与土地量相等,证明该岛屿全部沉没
}
cout << cnt;
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册