Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_algorithm
提交
25e421c2
S
skill_tree_algorithm
项目概览
CSDN 技术社区
/
skill_tree_algorithm
通知
9
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_algorithm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
25e421c2
编写于
11月 12, 2021
作者:
每日一练社区
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 25 exercises
上级
80e70db5
变更
25
展开全部
隐藏空白更改
内联
并排
Showing
25 changed file
with
1484 addition
and
2243 deletion
+1484
-2243
data/1.算法初阶/1.蓝桥杯-基础/1.猜年龄/solution.md
data/1.算法初阶/1.蓝桥杯-基础/1.猜年龄/solution.md
+1
-18
data/1.算法初阶/1.蓝桥杯-基础/17.乘积最大/solution.md
data/1.算法初阶/1.蓝桥杯-基础/17.乘积最大/solution.md
+0
-1
data/1.算法初阶/1.蓝桥杯-基础/18.错误票据/solution.md
data/1.算法初阶/1.蓝桥杯-基础/18.错误票据/solution.md
+79
-72
data/1.算法初阶/1.蓝桥杯-基础/19.猜字母/solution.md
data/1.算法初阶/1.蓝桥杯-基础/19.猜字母/solution.md
+74
-62
data/1.算法初阶/1.蓝桥杯-基础/20.成绩统计/solution.md
data/1.算法初阶/1.蓝桥杯-基础/20.成绩统计/solution.md
+76
-139
data/1.算法初阶/1.蓝桥杯-基础/21.次数差/solution.md
data/1.算法初阶/1.蓝桥杯-基础/21.次数差/solution.md
+97
-94
data/1.算法初阶/1.蓝桥杯-基础/8.第几天/solution.md
data/1.算法初阶/1.蓝桥杯-基础/8.第几天/solution.md
+0
-46
data/1.算法初阶/2.蓝桥杯-字符串/1.单词分析/solution.md
data/1.算法初阶/2.蓝桥杯-字符串/1.单词分析/solution.md
+102
-72
data/1.算法初阶/2.蓝桥杯-字符串/2.翻硬币/solution.md
data/1.算法初阶/2.蓝桥杯-字符串/2.翻硬币/solution.md
+81
-53
data/1.算法初阶/2.蓝桥杯-字符串/3.分类计数/solution.md
data/1.算法初阶/2.蓝桥杯-字符串/3.分类计数/solution.md
+33
-68
data/1.算法初阶/3.蓝桥杯-递归/1.带分数/solution.md
data/1.算法初阶/3.蓝桥杯-递归/1.带分数/solution.md
+138
-133
data/1.算法初阶/3.蓝桥杯-递归/2.抽签/solution.md
data/1.算法初阶/3.蓝桥杯-递归/2.抽签/solution.md
+40
-97
data/1.算法初阶/3.蓝桥杯-递归/3.打印图形/solution.md
data/1.算法初阶/3.蓝桥杯-递归/3.打印图形/solution.md
+36
-75
data/1.算法初阶/3.蓝桥杯-递归/4.等差数列/solution.md
data/1.算法初阶/3.蓝桥杯-递归/4.等差数列/solution.md
+26
-78
data/1.算法初阶/4.蓝桥杯-堆栈队列链表/1.堆的计数/solution.md
data/1.算法初阶/4.蓝桥杯-堆栈队列链表/1.堆的计数/solution.md
+25
-96
data/1.算法初阶/6.蓝桥杯-模拟/1.方格填数/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/1.方格填数/solution.md
+5
-102
data/1.算法初阶/6.蓝桥杯-模拟/10.放棋子/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/10.放棋子/solution.md
+8
-218
data/1.算法初阶/6.蓝桥杯-模拟/2.等腰三角形/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/2.等腰三角形/solution.md
+230
-139
data/1.算法初阶/6.蓝桥杯-模拟/3.承压计算/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/3.承压计算/solution.md
+40
-114
data/1.算法初阶/6.蓝桥杯-模拟/4.分巧克力/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/4.分巧克力/solution.md
+130
-57
data/1.算法初阶/6.蓝桥杯-模拟/5.颠倒的价牌/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/5.颠倒的价牌/solution.md
+151
-140
data/1.算法初阶/6.蓝桥杯-模拟/6.方程整数解/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/6.方程整数解/solution.md
+23
-103
data/1.算法初阶/6.蓝桥杯-模拟/7.7段码/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/7.7段码/solution.md
+5
-190
data/1.算法初阶/6.蓝桥杯-模拟/8.分糖果/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/8.分糖果/solution.md
+84
-76
data/1.算法初阶/6.蓝桥杯-模拟/9.夺冠概率/solution.md
data/1.算法初阶/6.蓝桥杯-模拟/9.夺冠概率/solution.md
+0
-0
未找到文件。
data/1.算法初阶/1.蓝桥杯-基础/1.猜年龄/solution.md
浏览文件 @
25e421c2
...
...
@@ -4,24 +4,7 @@
一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”
请你推算一下,他当时到底有多年轻。
以下代码的输出中包含了该数学家的真实年龄,请你从下面四个选项中选择正确答案。
```
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
;
}
```
请你从下面四个选项中选择正确答案。
## aop
...
...
data/1.算法初阶/1.蓝桥杯-基础/17.乘积最大/solution.md
浏览文件 @
25e421c2
...
...
@@ -75,7 +75,6 @@ using namespace std;
```
cpp
#define ll long long
#define inf 0x7fffffff
using
namespace
std
;
const
int
N
=
1e5
+
10
;
const
int
mod
=
1e9
+
9
;
int
n
,
k
;
...
...
data/1.算法初阶/1.蓝桥杯-基础/18.错误票据/solution.md
浏览文件 @
25e421c2
...
...
@@ -57,19 +57,15 @@
105 120
```
以下选项错误的是?
## aop
### before
```
cpp
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <bits/stdc++.h>
using
namespace
std
;
int
ans
[
10005
];
char
str
[
100001
];
```
### after
...
...
@@ -80,37 +76,31 @@ char str[100001];
## 答案
```
cpp
int
a
[
100000
];
int
main
()
{
int
n
;
int
i
,
n
,
count
=
0
,
k
;
char
ch
;
cin
>>
n
;
int
i
,
k
=
0
;
getchar
();
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(;;)
{
gets
(
str
);
char
*
p
;
p
=
strtok
(
str
,
" "
);
ans
[
k
++
]
=
atoi
(
p
);
while
(
p
)
{
p
=
strtok
(
NULL
,
" "
);
if
(
p
)
ans
[
k
++
]
=
atoi
(
p
);
}
cin
>>
k
;
a
[
k
]
++
;
ch
=
getchar
();
if
(
ch
==
'\n'
)
count
++
;
if
(
count
==
n
)
break
;
}
sort
(
ans
,
ans
+
k
);
int
ans1
,
ans2
;
for
(
i
=
0
;
i
<
k
-
1
;
i
++
)
for
(
i
=
1
;
i
<
10000
;
i
++
)
{
if
(
ans
[
i
+
1
]
-
ans
[
i
]
==
2
)
{
ans1
=
ans
[
i
]
+
1
;
}
if
(
ans
[
i
+
1
]
==
ans
[
i
])
ans2
=
ans
[
i
];
if
(
a
[
i
-
1
]
!=
0
&&
a
[
i
+
1
]
!=
0
&&
a
[
i
]
==
0
)
cout
<<
i
<<
" "
;
if
(
a
[
i
]
==
2
)
cout
<<
i
+
1
<<
" "
<<
endl
;
}
cout
<<
ans1
<<
" "
<<
ans2
;
}
```
## 选项
...
...
@@ -119,80 +109,97 @@ int main()
### A
```
cpp
int
convert
(
string
s
)
{
stringstream
str
;
int
ex
;
str
<<
s
;
str
>>
ex
;
return
ex
;
}
int
main
()
{
int
n
;
cin
>>
n
;
int
i
,
k
=
0
;
int
line
;
cin
>>
line
;
vector
<
int
>
a
;
getchar
();
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
line
;
i
++
)
{
gets
(
str
);
char
*
p
;
p
=
strtok
(
str
,
" "
);
ans
[
k
++
]
=
atoi
(
p
);
while
(
p
)
string
s
;
getline
(
cin
,
s
);
stringstream
str
(
s
);
string
s2
;
while
(
getline
(
str
,
s2
,
' '
))
{
p
=
strtok
(
NULL
,
" "
)
;
if
(
p
)
ans
[
k
]
=
atoi
(
p
);
int
ex
;
ex
=
convert
(
s2
);
a
.
push_back
(
ex
);
}
}
sort
(
ans
,
ans
+
k
);
int
ans1
,
ans2
;
for
(
i
=
0
;
i
<
k
-
1
;
i
++
)
int
result1
,
result2
;
sort
(
a
.
begin
(),
a
.
end
());
for
(
int
i
=
1
;
i
<
a
.
size
();
i
++
)
{
if
(
ans
[
i
+
1
]
-
ans
[
i
]
==
2
)
{
ans1
=
ans
[
i
]
+
1
;
}
if
(
ans
[
i
+
1
]
==
ans
[
i
])
ans2
=
ans
[
i
];
if
(
a
[
i
]
-
a
[
i
-
1
]
==
2
)
result1
=
a
[
i
]
-
1
;
if
(
a
[
i
]
==
a
[
i
-
1
])
result2
=
a
[
i
];
}
cout
<<
ans1
<<
" "
<<
ans
2
;
cout
<<
result1
<<
" "
<<
result
2
;
}
```
### B
```
cpp
int
a
[
10005
];
int
main
()
{
int
n
;
cin
>>
n
;
int
i
,
k
=
0
;
getchar
();
int
k
=
0
;
char
ch
=
' '
;
int
i
,
j
=
0
,
t
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
gets
(
str
);
char
*
p
;
p
=
strtok
(
str
,
" "
);
ans
[
k
++
]
=
atoi
(
p
);
while
(
p
)
while
(
ch
!=
'\n'
)
{
p
=
strtok
(
NULL
,
" "
);
if
(
p
)
ans
[
k
++
]
=
atoi
(
p
);
cin
>>
t
;
ch
=
getchar
();
a
[
j
++
]
=
t
;
k
++
;
}
ch
=
' '
;
}
sort
(
a
ns
,
ans
+
k
);
int
ans1
,
ans2
;
for
(
i
=
0
;
i
<
k
-
1
;
i
++
)
sort
(
a
,
a
+
k
);
int
ans1
=
0
,
ans2
=
0
;
for
(
j
=
0
;
j
<
k
-
1
;
j
++
)
{
if
(
ans
[
i
+
1
]
-
ans
[
i
]
==
2
)
{
ans1
=
ans
[
i
+
1
];
}
if
(
ans
[
i
+
1
]
==
ans
[
i
])
ans2
=
ans
[
i
];
if
(
ans1
&&
ans2
)
break
;
if
(
a
[
j
]
==
a
[
j
+
1
]
-
1
)
continue
;
else
if
(
a
[
j
]
==
a
[
j
+
1
])
ans2
=
a
[
j
];
else
ans1
=
a
[
j
]
+
1
;
}
cout
<<
ans1
<<
" "
<<
ans2
;
return
0
;
}
```
### C
```
cpp
int
ans
[
10005
];
char
str
[
100001
];
int
main
()
{
int
n
;
...
...
@@ -216,7 +223,7 @@ int main()
int
ans1
,
ans2
;
for
(
i
=
0
;
i
<
k
-
1
;
i
++
)
{
if
(
ans
[
i
+
1
]
-
ans
[
i
]
==
1
)
if
(
ans
[
i
+
1
]
-
ans
[
i
]
==
2
)
{
ans1
=
ans
[
i
]
+
1
;
}
...
...
data/1.算法初阶/1.蓝桥杯-基础/19.猜字母/solution.md
浏览文件 @
25e421c2
...
...
@@ -4,13 +4,14 @@
接下来删除第1个字母(即开头的字母a),以及第3个,第5个等所有奇数位置的字母。
得到的新串再进行删除奇数位置字母的动作。如此下去,最后只剩下一个字母,请写出该字母。
以下程序哪项运行后不能得到正确答案?
## aop
### before
```
cpp
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using
namespace
std
;
```
### after
...
...
@@ -22,23 +23,31 @@ using namespace std;
## 答案
```
cpp
int
a
[
2014
];
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
;
int
count
=
2014
;
for
(
int
i
=
0
;
i
<
2014
;
i
++
)
{
a
[
i
]
=
i
+
1
;
}
do
{
for
(
int
i
=
0
;
i
<=
count
-
1
;
i
+=
2
)
a
[
i
]
=
0
;
count
=
0
;
for
(
int
j
=
0
;
j
<=
2013
;
j
++
)
{
if
(
a
[
j
]
!=
0
)
{
a
[
count
]
=
a
[
j
];
a
[
j
]
=
0
;
count
++
;
}
}
}
while
(
count
!=
1
);
cout
<<
char
(
'a'
+
(
a
[
0
]
%
19
));
return
0
;
}
```
## 选项
...
...
@@ -49,21 +58,23 @@ int main()
```
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
;
string
s
=
"abcdefghijklmnopqrs"
;
string
str
;
for
(
int
i
=
0
;
i
<
106
;
i
++
)
{
str
+=
s
;
}
while
(
str
.
length
()
>
1
)
{
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++
)
{
str
.
erase
(
i
,
1
);
}
}
cout
<<
str
;
return
0
;
}
```
...
...
@@ -72,21 +83,23 @@ int main()
```
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
;
char
a
[
2015
];
int
t
=
0
;
for
(
int
j
=
0
;
j
<
106
;
j
++
)
for
(
int
i
=
0
;
i
<
19
;
i
++
)
a
[
t
++
]
=
'a'
+
i
;
a
[
t
]
=
0
;
int
k
;
while
(
t
!=
1
)
{
k
=
0
;
for
(
int
j
=
1
;
j
<
t
;
j
+=
2
)
a
[
k
++
]
=
a
[
j
];
a
[
k
]
=
'\0'
;
t
=
k
;
}
cout
<<
a
<<
endl
;
return
0
;
}
```
...
...
@@ -95,20 +108,19 @@ int main()
```
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
;
vector
<
char
>
vc1
;
int
i
;
for
(
i
=
0
;
i
<
2014
;
i
++
)
vc1
.
push_back
(
'a'
+
(
i
%
19
));
while
(
vc1
.
size
()
!=
1
)
{
vector
<
char
>
vc2
;
for
(
i
=
1
;
i
<
vc1
.
size
();
i
+=
2
)
vc2
.
push_back
(
vc1
[
i
]);
vc1
.
assign
(
vc2
.
begin
(),
vc2
.
end
());
}
cout
<<
vc1
[
0
]
<<
endl
;
return
0
;
}
```
data/1.算法初阶/1.蓝桥杯-基础/20.成绩统计/solution.md
浏览文件 @
25e421c2
...
...
@@ -24,13 +24,47 @@ yx2
yx1
```
请从以下四个选项中选择空白处的内容。
```
cpp
#include <bits/stdc++.h>
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
;
__________________
}
cout
<<
maxs
<<
endl
<<
mins
;
return
0
;
}
```
## aop
### before
```
cpp
#include <iostream>
using
namespace
std
;
```
### after
...
...
@@ -41,41 +75,16 @@ using namespace std;
## 答案
```
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
;
}
if
(
min
>
sum
)
{
min
=
sum
;
mins
=
a
[
i
].
xm
;
}
if
(
max
<
sum
)
{
max
=
sum
;
maxs
=
a
[
i
].
xm
;
}
```
## 选项
...
...
@@ -83,116 +92,44 @@ int main()
### 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
;
}
if
(
min
<
sum
)
{
min
=
sum
;
mins
=
a
[
i
].
xm
;
}
if
(
max
>
sum
)
{
max
=
sum
;
maxs
=
a
[
i
].
xm
;
}
```
### 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
;
}
}
if
(
min
>
sum
)
{
max
=
sum
;
mins
=
a
[
i
].
xm
;
}
if
(
max
<
sum
)
{
min
=
sum
;
maxs
=
a
[
i
].
xm
;
}
```
### 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
;
}
if
(
min
>
sum
)
{
min
=
sum
;
maxs
=
a
[
i
].
xm
;
}
if
(
max
<
sum
)
{
max
=
sum
;
mins
=
a
[
i
].
xm
;
}
```
data/1.算法初阶/1.蓝桥杯-基础/21.次数差/solution.md
浏览文件 @
25e421c2
...
...
@@ -42,13 +42,15 @@ bbccccddaaaacccc
6
```
以下选项错误的是?
## aop
### before
```
cpp
#include <
stdio
.h>
#include <string.h>
#include <
bits/stdc++
.h>
using
namespace
std
;
```
### after
...
...
@@ -59,31 +61,31 @@ bbccccddaaaacccc
## 答案
```
cpp
int
main
()
const
int
N
=
1010
;
int
cnt
[
26
];
char
a
[
N
];
char
b
[
27
]
=
{
"abcdefghijklmnopqrstuvwxyz"
};
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
;
cin
>>
a
;
for
(
int
i
=
0
;
i
<
26
;
i
++
)
for
(
int
j
=
0
;
a
[
j
];
j
++
)
if
(
b
[
i
]
==
a
[
j
+
1
])
cnt
[
i
]
++
;
int
maxn
=
0
,
minn
=
1000
;
for
(
int
i
=
0
;
i
<=
26
;
i
++
)
if
(
cnt
[
i
])
{
maxn
=
max
(
maxn
,
cnt
[
i
]);
minn
=
min
(
minn
,
cnt
[
i
]);
}
cout
<<
maxn
-
minn
<<
endl
;
return
0
;
}
```
## 选项
...
...
@@ -91,89 +93,90 @@ int main()
### A
```
cpp
int
main
()
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
;
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
;
}
```
### B
```
cpp
int
main
()
int
cnt
[
1001
];
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
;
string
s
;
cin
>>
s
;
int
max1
=
-
1
,
min1
=
1001
;
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++
)
{
for
(
int
j
=
0
;
j
<=
s
.
length
();
j
++
)
{
if
(
s
[
i
]
==
s
[
j
])
{
cnt
[
i
]
++
;
}
}
}
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++
)
{
if
(
cnt
[
i
]
>
max1
)
{
max1
=
cnt
[
i
];
}
if
(
cnt
[
i
]
<
min1
)
{
min1
=
cnt
[
i
];
}
}
cout
<<
max1
-
min1
<<
endl
;
return
0
;
}
```
### C
```
cpp
int
main
()
int
a
[
26
];
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
;
string
str
;
cin
>>
str
;
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++
)
{
a
[
str
[
i
]
-
'a'
]
++
;
}
sort
(
a
,
a
+
26
);
for
(
int
i
=
0
;
i
<
26
;
i
++
)
{
if
(
a
[
i
]
!=
0
)
{
cout
<<
a
[
25
]
-
a
[
i
]
<<
endl
;
break
;
}
}
return
0
;
}
```
data/1.算法初阶/1.蓝桥杯-基础/8.第几天/solution.md
浏览文件 @
25e421c2
...
...
@@ -3,52 +3,6 @@
y年m月d日是哪一年的第几天。
比如y年的1月1日是那一年的第一天,那么2000年7月7日是那一年的第几天。
**输入**
```
2000 7 7
```
请通过以下代码,选出正确答案。
```
cpp
#include <bits/stdc++.h>
using
namespace
std
;
bool
is_leap
(
int
year
)
{
return
(
year
%
4
==
0
&&
year
%
100
!=
0
)
||
year
%
400
==
0
;
}
int
main
()
{
int
y
,
m
,
d
,
ans
=
0
;
cin
>>
y
>>
m
>>
d
;
int
L_m_d
[
12
]
=
{
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
int
nonL_m_d
[
12
]
=
{
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
if
(
is_leap
(
y
))
{
for
(
int
i
=
0
;
i
<
(
m
-
1
);
i
++
)
{
ans
+=
L_m_d
[
i
];
}
ans
+=
d
;
}
else
{
for
(
int
i
=
0
;
i
<
(
m
-
1
);
i
++
)
{
ans
+=
nonL_m_d
[
i
];
}
ans
+=
d
;
}
cout
<<
ans
<<
endl
;
return
0
;
}
```
## aop
### before
...
...
data/1.算法初阶/2.蓝桥杯-字符串/1.单词分析/solution.md
浏览文件 @
25e421c2
...
...
@@ -40,13 +40,15 @@ o 6
对于所有的评测用例,输入的单词长度不超过 1000。
以下选项错误的是?
## aop
### before
```
cpp
#include
"stdio.h"
#include "string.h"
#include
<bits/stdc++.h>
using
namespace
std
;
```
### after
...
...
@@ -59,32 +61,27 @@ o 6
```
cpp
int
main
()
{
int
a
[
128
]
=
{
0
};
char
s
[
1000
];
scanf
(
"%s"
,
s
);
int
len
=
strlen
(
s
);
int
max
=
0
;
char
t
=
0
;
char
a
[
1005
];
scanf
(
"%s"
,
a
);
int
len
;
len
=
strlen
(
a
);
int
b
[
26
]
=
{
0
};
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
a
[
s
[
i
]]
++
;
if
(
max
<
a
[
s
[
i
]])
{
max
=
a
[
s
[
i
]];
t
=
s
[
i
];
}
else
if
(
max
==
a
[
s
[
i
]])
b
[
a
[
i
]
+
'a'
]
++
;
}
int
max1
=
0
,
j
;
for
(
int
i
=
0
;
i
<
26
;
i
++
)
{
if
(
max1
<
b
[
i
])
{
if
(
t
>
s
[
i
])
{
t
=
s
[
i
];
}
max1
=
b
[
i
];
j
=
i
;
}
}
printf
(
"%c
\n
%d"
,
t
,
max
);
}
cout
<<
char
(
'a'
+
j
)
<<
endl
<<
max1
;
}
```
## 选项
...
...
@@ -93,68 +90,103 @@ int main()
### A
```
cpp
#define MAX 1010
int
s
[
MAX
];
int
main
()
{
int
a
[
128
]
=
{
0
};
char
s
[
1000
];
scanf
(
"%s"
,
s
);
int
len
=
strlen
(
s
);
string
str
;
cin
>>
str
;
int
n
=
str
.
size
();
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
a
=
str
[
i
]
-
'a'
;
s
[
a
]
++
;
}
int
max
=
0
;
char
t
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
char
ch
;
for
(
int
i
=
0
;
i
<
MAX
;
i
++
)
{
a
[
s
[
i
]]
++
;
if
(
max
>
a
[
s
[
i
]])
{
max
=
a
[
s
[
i
]];
t
=
s
[
i
];
}
else
if
(
max
==
a
[
s
[
i
]])
if
(
max
<=
s
[
i
])
{
if
(
t
>
s
[
i
])
if
(
max
<
s
[
i
])
{
t
=
s
[
i
];
max
=
s
[
i
];
ch
=
(
char
)(
i
+
'a'
);
}
else
if
(
max
==
s
[
i
])
{
max
=
s
[
i
];
ch
=
ch
;
}
}
}
printf
(
"%c
\n
%d"
,
t
,
max
);
}
cout
<<
ch
<<
endl
;
cout
<<
max
<<
endl
;
return
0
;
}
```
### B
```
cpp
char
m
[
1005
];
int
n
[
1005
];
char
c
;
bool
b
[
1005
];
string
str
;
int
main
()
{
int
a
[
128
]
=
{
0
};
char
s
[
1000
];
scanf
(
"%s"
,
s
);
int
len
=
strlen
(
s
);
int
max
=
0
;
char
t
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
cin
>>
str
;
memset
(
b
,
false
,
sizeof
(
b
));
for
(
int
i
=
0
;
i
<
str
.
size
();
i
++
)
{
a
[
s
[
i
]]
++
;
if
(
max
>
a
[
s
[
i
]])
{
max
=
a
[
s
[
i
]];
t
=
s
[
i
+
1
];
}
else
if
(
max
==
a
[
s
[
i
]])
while
(
b
[
i
])
{
if
(
t
>
s
[
i
])
i
++
;
}
m
[
i
]
=
str
[
i
];
b
[
i
]
=
true
;
n
[
i
]
=
1
;
for
(
int
j
=
i
+
1
;
j
<
str
.
size
();
j
++
)
{
if
(
m
[
i
]
==
str
[
j
])
{
t
=
s
[
i
];
n
[
i
]
++
;
b
[
j
]
=
true
;
}
}
}
printf
(
"%c
\n
%d"
,
t
,
max
);
if
(
max
<=
n
[
i
])
{
if
(
max
==
n
[
i
])
{
if
((
c
-
'a'
)
<=
(
m
[
i
]
-
'a'
))
{
c
=
c
;
}
else
{
c
=
m
[
i
];
}
}
else
{
max
=
n
[
i
];
c
=
m
[
i
];
}
}
}
cout
<<
c
<<
endl
;
cout
<<
max
<<
endl
;
return
0
;
}
```
...
...
@@ -163,23 +195,22 @@ int main()
```
cpp
int
main
()
{
int
a
[
128
]
=
{
0
};
char
s
[
1000
];
scanf
(
"%s"
,
s
);
int
len
=
strlen
(
s
);
int
max
=
0
;
char
t
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
a
[
s
[
i
]]
++
;
if
(
max
<
a
[
s
[
i
]])
{
{
max
=
a
[
s
[
i
]];
t
=
s
[
i
+
1
];
}
t
=
s
[
i
];
}
else
if
(
max
==
a
[
s
[
i
]])
{
if
(
t
>
s
[
i
])
...
...
@@ -187,8 +218,7 @@ int main()
t
=
s
[
i
];
}
}
}
}
printf
(
"%c
\n
%d"
,
t
,
max
);
}
```
data/1.算法初阶/2.蓝桥杯-字符串/2.翻硬币/solution.md
浏览文件 @
25e421c2
...
...
@@ -45,6 +45,8 @@ o****o****
1
```
以下选项错误的是?
## aop
### before
...
...
@@ -62,33 +64,23 @@ using namespace std;
## 答案
```
cpp
char
a
[
1005
],
b
[
1005
];
int
len
,
i
=
0
,
ans
=
0
;
int
main
()
{
string
a
,
b
;
cin
>>
a
>>
b
;
int
a1
=
a
.
size
(),
b1
=
b
.
size
(),
ans
=
0
;
for
(
int
i
=
0
;
i
<
a1
;
i
++
)
scanf
(
"%s%s"
,
a
,
b
);
len
=
strlen
(
a
);
while
(
i
<
len
)
{
if
(
a
[
i
]
==
b
[
i
])
{
continue
;
}
else
if
(
a
[
i
]
!=
b
[
i
])
{
ans
++
;
a
[
i
]
=
b
[
i
];
if
(
a
[
i
+
1
]
==
'*'
)
{
a
[
i
+
1
]
=
'o'
;
}
else
{
a
[
i
+
1
]
=
'*'
;
}
a
[
i
+
1
]
=
(
a
[
i
+
1
]
==
'*'
?
'*'
:
'o'
);
++
ans
;
}
++
i
;
}
cout
<<
ans
<<
endl
;
return
0
;
printf
(
"%d
\n
"
,
ans
);
}
```
## 选项
...
...
@@ -97,32 +89,63 @@ int main()
### A
```
cpp
int
main
()
char
a
[
1005
],
b
[
1005
];
struct
node
{
string
a
,
b
;
cin
>>
a
>>
b
;
int
a1
=
a
.
size
(),
b1
=
b
.
size
(),
ans
=
0
;
for
(
int
i
=
0
;
i
<
a1
;
i
++
)
char
ff
[
1005
];
int
step
;
};
void
bfs
()
{
queue
<
node
>
q
;
node
ll
;
strcpy
(
ll
.
ff
,
a
);
ll
.
step
=
0
;
q
.
push
(
ll
);
while
(
!
q
.
empty
())
{
if
(
a
[
i
]
==
b
[
i
])
node
tmp
;
tmp
=
q
.
front
();
q
.
pop
();
if
(
!
strcmp
(
tmp
.
ff
,
b
))
{
continue
;
printf
(
"%d
\n
"
,
tmp
.
step
);
return
;
}
else
int
num
=
strlen
(
tmp
.
ff
);
for
(
int
i
=
0
;
i
<
num
-
1
;
i
++
)
{
ans
++
;
a
[
i
]
=
b
[
i
];
if
(
a
[
i
+
1
]
==
'*'
)
{
a
[
i
]
=
'o'
;
}
node
now
;
now
=
tmp
;
now
.
step
++
;
if
(
now
.
ff
[
i
]
==
'*'
)
now
.
ff
[
i
]
=
'o'
;
else
{
a
[
i
]
=
'*'
;
}
now
.
ff
[
i
]
=
'*'
;
if
(
now
.
ff
[
i
+
1
]
==
'*'
)
now
.
ff
[
i
+
1
]
=
'o'
;
else
now
.
ff
[
i
+
1
]
=
'*'
;
q
.
push
(
now
);
}
}
cout
<<
ans
<<
endl
;
}
int
main
()
{
while
(
~
scanf
(
"%s"
,
a
))
{
scanf
(
"%s"
,
b
);
bfs
();
}
return
0
;
}
```
...
...
@@ -132,20 +155,24 @@ int main()
```
cpp
int
main
()
{
string
a
,
b
;
string
a
;
string
b
;
cin
>>
a
>>
b
;
int
a1
=
a
.
size
(),
b1
=
b
.
size
(),
ans
=
0
;
for
(
int
i
=
0
;
i
<
a
1
;
i
++
)
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
a
.
length
()
;
i
++
)
{
if
(
a
[
i
]
=
=
b
[
i
])
if
(
a
[
i
]
!
=
b
[
i
])
{
continue
;
}
else
{
ans
++
;
a
[
i
]
=
b
[
i
];
if
(
a
[
i
]
==
'*'
)
{
a
[
i
]
=
'o'
;
}
else
{
a
[
i
]
=
'*'
;
}
if
(
a
[
i
+
1
]
==
'*'
)
{
a
[
i
+
1
]
=
'o'
;
}
...
...
@@ -153,9 +180,10 @@ int main()
{
a
[
i
+
1
]
=
'*'
;
}
cnt
++
;
}
}
cout
<<
ans
<<
endl
;
cout
<<
cnt
;
return
0
;
}
```
...
...
@@ -178,13 +206,13 @@ int main()
{
ans
++
;
a
[
i
]
=
b
[
i
];
if
(
a
[
i
]
==
'*'
)
if
(
a
[
i
+
1
]
==
'*'
)
{
a
[
i
+
1
]
=
'
*
'
;
a
[
i
+
1
]
=
'
o
'
;
}
else
{
a
[
i
+
1
]
=
'
o
'
;
a
[
i
+
1
]
=
'
*
'
;
}
}
}
...
...
data/1.算法初阶/2.蓝桥杯-字符串/3.分类计数/solution.md
浏览文件 @
25e421c2
...
...
@@ -29,13 +29,35 @@
对于所有评测用例,字符串由可见字符组成,长度不超过 100。
请您补全以下代码:
```
cpp
#include <bits/stdc++.h>
using
namespace
std
;
int
main
(
int
argc
,
char
**
argv
)
{
string
str
;
cin
>>
str
;
int
A
=
0
,
a
=
0
,
number
=
0
;
int
len
=
str
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
__________________
}
cout
<<
A
<<
endl
;
cout
<<
a
<<
endl
;
cout
<<
number
<<
endl
;
return
0
;
}
```
## aop
### before
```
cpp
#include <iostream>
using
namespace
std
;
```
### after
...
...
@@ -46,14 +68,6 @@ using namespace std;
## 答案
```
cpp
int
main
(
int
argc
,
char
**
argv
)
{
string
str
;
cin
>>
str
;
int
A
=
0
,
a
=
0
,
number
=
0
;
int
len
=
str
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
str
[
i
]
<=
'9'
&&
str
[
i
]
>=
'0'
)
{
number
++
;
...
...
@@ -66,13 +80,6 @@ int main(int argc, char **argv)
{
a
++
;
}
}
cout
<<
A
<<
endl
;
cout
<<
a
<<
endl
;
cout
<<
number
<<
endl
;
return
0
;
}
```
## 选项
...
...
@@ -80,92 +87,50 @@ int main(int argc, char **argv)
### A
```
cpp
int
main
(
int
argc
,
char
**
argv
)
{
string
str
;
cin
>>
str
;
int
A
=
0
,
a
=
0
,
number
=
0
;
int
len
=
str
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
str
[
i
]
<
'9'
&&
str
[
i
]
>
'0'
)
if
(
'0'
<=
str
[
i
]
<=
'0'
)
{
number
++
;
}
if
(
str
[
i
]
<
'Z'
&&
str
[
i
]
>
'A
'
)
if
(
'A'
<=
str
[
i
]
<=
'Z
'
)
{
A
++
;
}
if
(
str
[
i
]
<
'z'
&&
str
[
i
]
>
'a
'
)
if
(
'a'
<=
str
[
i
]
<=
'z
'
)
{
a
++
;
}
}
cout
<<
A
<<
endl
;
cout
<<
a
<<
endl
;
cout
<<
number
<<
endl
;
return
0
;
}
```
### B
```
cpp
int
main
(
int
argc
,
char
**
argv
)
{
string
str
;
cin
>>
str
;
int
A
=
0
,
a
=
0
,
number
=
0
;
int
len
=
str
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
str
[
i
]
<
71
&&
str
[
i
]
>
60
)
if
(
str
[
i
]
<=
'9'
&
str
[
i
]
>=
'0'
)
{
number
++
;
}
if
(
str
[
i
]
<
132
&&
str
[
i
]
>
101
)
if
(
str
[
i
]
<
=
'Z'
&
str
[
i
]
>=
'A'
)
{
A
++
;
}
if
(
str
[
i
]
<
172
&&
str
[
i
]
>
141
)
if
(
str
[
i
]
<
=
'z'
&
str
[
i
]
>=
'a'
)
{
a
++
;
}
}
cout
<<
A
<<
endl
;
cout
<<
a
<<
endl
;
cout
<<
number
<<
endl
;
return
0
;
}
```
### C
```
cpp
int
main
(
int
argc
,
char
**
argv
)
{
string
str
;
cin
>>
str
;
int
A
=
0
,
a
=
0
,
number
=
0
;
int
len
=
str
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
str
[
i
]
<
39
&&
str
[
i
]
>
30
)
if
(
str
[
i
]
<
'9'
&&
str
[
i
]
>
'0'
)
{
number
++
;
}
if
(
str
[
i
]
<
132
&&
str
[
i
]
>
101
)
if
(
str
[
i
]
<
'Z'
&&
str
[
i
]
>
'A'
)
{
A
++
;
}
if
(
str
[
i
]
<
=
'z'
&&
str
[
i
]
>=
'a'
)
if
(
str
[
i
]
<
'z'
&&
str
[
i
]
>
'a'
)
{
a
++
;
}
}
cout
<<
A
<<
endl
;
cout
<<
a
<<
endl
;
cout
<<
number
<<
endl
;
return
0
;
}
```
data/1.算法初阶/3.蓝桥杯-递归/1.带分数/solution.md
浏览文件 @
25e421c2
...
...
@@ -41,89 +41,53 @@
6
```
以下错误的一项是?
## aop
### before
```
cpp
#include <stdio.h>
int
x
=
0
,
number
=
0
,
count
=
0
;
void
Swap
(
int
&
a
,
int
&
b
)
{
int
temp
=
a
;
a
=
b
;
b
=
temp
;
}
int
getNum
(
int
list
[],
int
f
,
int
r
)
{
int
i
=
0
,
num
=
0
;
for
(
i
=
f
;
i
<=
r
;
i
++
)
num
=
list
[
i
]
+
num
*
10
;
return
num
;
}
#include <bits/stdc++.h>
using
namespace
std
;
```
### after
```
cpp
int
main
()
{
int
temp
=
0
;
int
list
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
scanf
(
"%d"
,
&
number
);
temp
=
number
;
while
(
temp
!=
0
)
{
++
x
;
temp
/=
10
;
}
Prim
(
list
,
0
,
9
);
printf
(
"%d"
,
count
);
return
0
;
}
```
## 答案
```
cpp
void
Prim
(
int
list
[],
int
k
,
int
m
)
int
main
(
)
{
if
(
k
==
m
-
1
)
int
n
,
ans
=
0
;
scanf
(
"%d"
,
&
n
);
string
s
=
"123456789"
;
do
{
int
a
=
0
,
b
=
0
,
c
=
0
,
bLast
=
0
;
for
(
int
i
=
0
;
i
<
x
;
i
++
)
for
(
int
i
=
1
;
i
<=
7
;
++
i
)
{
a
=
getNum
(
list
,
0
,
i
);
bLast
=
((
number
-
a
)
*
list
[
8
])
%
10
;
for
(
int
j
=
i
+
(
8
-
i
)
/
2
;
j
<
8
;
j
++
)
{
if
(
list
[
j
]
==
bLast
)
{
b
=
getNum
(
list
,
i
+
1
,
j
);
c
=
getNum
(
list
,
j
+
1
,
8
);
if
(
b
%
c
==
0
&&
a
+
b
/
c
==
number
)
{
string
a
=
s
.
substr
(
0
,
i
);
int
inta
=
atoi
(
a
.
c_str
());
if
(
inta
>=
n
)
break
;
++
count
;
}
break
;
}
for
(
int
j
=
i
;
j
<=
9
-
i
;
++
j
)
{
string
b
=
s
.
substr
(
i
,
j
);
string
c
=
s
.
substr
(
i
+
j
);
int
intb
=
atoi
(
b
.
c_str
());
int
intc
=
atoi
(
c
.
c_str
());
if
(
intb
%
intc
==
0
&&
inta
+
intb
/
intc
==
n
)
ans
++
;
}
}
}
else
{
for
(
int
i
=
k
;
i
<
m
;
i
++
)
{
Swap
(
list
[
k
],
list
[
i
]);
Prim
(
list
,
k
+
1
,
m
);
Swap
(
list
[
k
],
list
[
i
]);
}
}
}
while
(
next_permutation
(
s
.
begin
(),
s
.
end
()));
printf
(
"%d
\n
"
,
ans
);
return
0
;
}
```
## 选项
...
...
@@ -132,119 +96,160 @@ void Prim(int list[], int k, int m)
### A
```
cpp
void
Prim
(
int
list
[],
int
k
,
int
m
)
int
visit
[
10
]
=
{
0
};
int
s
[
10
];
int
ans
=
0
;
int
N
;
void
found
(
int
s
[])
{
if
(
k
==
m
-
1
)
int
x
,
y
,
z
;
for
(
int
i
=
1
;
i
<
9
;
i
++
)
{
int
a
=
0
,
b
=
0
,
c
=
0
,
bLast
=
0
;
for
(
int
i
=
0
;
i
<
x
;
i
++
)
for
(
int
j
=
i
+
1
;
j
<
9
;
j
++
)
{
a
=
getNum
(
list
,
0
,
i
);
bLast
=
((
number
-
a
)
*
list
[
8
])
%
10
;
for
(
int
j
=
i
+
(
8
-
i
)
/
2
;
j
<
8
;
j
++
)
x
=
y
=
z
=
0
;
for
(
int
k
=
0
;
k
<
9
;
k
++
)
{
if
(
list
[
j
]
==
bLast
)
{
b
=
getNum
(
list
,
i
,
j
);
c
=
getNum
(
list
,
j
,
8
);
if
(
b
%
c
==
0
&&
a
+
b
/
c
==
number
)
{
++
count
;
}
break
;
}
if
(
k
<
i
)
x
=
x
*
10
+
s
[
k
+
1
];
else
if
(
k
<
j
)
y
=
y
*
10
+
s
[
k
+
1
];
else
z
=
z
*
10
+
s
[
k
+
1
];
}
if
(
y
%
z
==
0
&&
x
+
y
/
z
==
N
)
{
ans
++
;
}
}
}
}
void
dfs
(
int
pos
,
int
n
)
{
if
(
pos
==
n
)
found
(
s
);
else
{
for
(
int
i
=
k
;
i
<
m
;
i
++
)
for
(
int
i
=
1
;
i
<=
9
;
i
++
)
{
Swap
(
list
[
k
],
list
[
i
]);
Prim
(
list
,
k
+
1
,
m
);
Swap
(
list
[
k
],
list
[
i
]);
if
(
!
visit
[
i
])
{
s
[
pos
]
=
i
;
visit
[
i
]
=
1
;
dfs
(
pos
+
1
,
n
);
visit
[
i
]
=
0
;
}
}
}
}
int
main
()
{
cin
>>
N
;
dfs
(
1
,
10
);
cout
<<
ans
<<
endl
;
return
0
;
}
```
### B
```
cpp
void
Prim
(
int
list
[],
int
k
,
int
m
)
int
parse
(
const
char
*
arr
,
int
pos
,
int
len
)
{
int
ans
=
0
;
int
t
=
1
;
for
(
int
i
=
pos
+
len
-
1
;
i
>=
pos
;
i
--
)
{
ans
+=
(
arr
[
i
]
-
'0'
)
*
t
;
t
*=
10
;
}
return
ans
;
}
int
main
()
{
if
(
k
==
m
-
1
)
int
N
;
cin
>>
N
;
int
ans
=
0
;
string
s
=
"123456789"
;
do
{
int
a
=
0
,
b
=
0
,
c
=
0
,
bLast
=
0
;
for
(
int
i
=
0
;
i
<
x
;
i
++
)
const
char
*
str
=
s
.
c_str
()
;
for
(
int
i
=
0
;
i
<
=
7
;
i
++
)
{
a
=
getNum
(
list
,
0
,
i
);
bLast
=
((
number
-
a
)
*
list
[
8
])
%
10
;
for
(
int
j
=
i
+
(
8
-
i
)
/
2
;
j
<
8
;
j
++
)
int
inta
=
parse
(
str
,
0
,
i
);
if
(
inta
>=
N
)
break
;
for
(
int
j
=
1
;
j
<=
9
-
1
-
i
;
j
++
)
{
b
=
getNum
(
list
,
i
,
j
);
c
=
getNum
(
list
,
j
,
8
);
if
(
b
%
c
==
0
&&
a
+
b
/
c
==
number
)
int
intb
=
parse
(
str
,
i
,
j
);
int
intc
=
parse
(
str
,
i
+
j
,
9
-
i
-
j
);
if
(
intb
%
intc
==
0
&&
inta
+
intb
/
intc
==
N
)
{
++
count
;
ans
++
;
}
break
;
}
}
}
else
{
for
(
int
i
=
k
;
i
<
m
;
i
++
)
{
}
while
(
next_permutation
(
s
.
begin
(),
s
.
end
()));
Swap
(
list
[
k
],
list
[
i
]);
Prim
(
list
,
k
+
1
,
m
);
Swap
(
list
[
k
],
list
[
i
]);
}
}
cout
<<
ans
;
return
0
;
}
```
### C
```
cpp
void
Prim
(
int
list
[],
int
k
,
int
m
)
int
a
[
10
]
=
{
0
};
int
Division
(
int
m
)
{
if
(
k
==
m
-
1
)
int
t
;
while
(
m
)
{
int
a
=
0
,
b
=
0
,
c
=
0
,
bLast
=
0
;
for
(
int
i
=
0
;
i
<
x
;
i
++
)
t
=
m
%
1
0
;
if
(
t
==
0
)
{
a
=
getNum
(
list
,
0
,
i
);
bLast
=
((
number
-
a
)
*
list
[
8
])
%
10
;
for
(
int
j
=
i
+
(
8
-
i
)
/
2
;
j
<
8
;
j
++
)
{
if
(
list
[
j
]
==
bLast
)
{
b
=
getNum
(
list
,
i
+
1
,
j
);
c
=
getNum
(
list
,
j
+
1
,
8
);
++
count
;
break
;
}
}
return
0
;
}
a
[
t
]
++
;
m
=
m
/
10
;
}
else
return
1
;
}
int
main
()
{
int
i
,
k
,
j
;
int
number
,
ans
=
0
,
flag
;
cin
>>
number
;
for
(
i
=
1
;
i
<
number
;
i
++
)
{
for
(
int
i
=
k
;
i
<
m
;
i
++
)
for
(
j
=
1
;
j
<=
4938
;
j
++
)
{
Swap
(
list
[
k
],
list
[
i
]);
Prim
(
list
,
k
+
1
,
m
);
Swap
(
list
[
k
],
list
[
i
]);
memset
(
a
,
0
,
sizeof
(
a
));
k
=
(
number
-
i
)
*
j
;
if
(
Division
(
i
)
&&
Division
(
j
)
&&
Division
(
k
))
{
flag
=
1
;
for
(
int
x
=
1
;
x
<
10
;
x
++
)
{
if
(
a
[
x
]
!=
1
)
{
flag
=
0
;
break
;
}
}
if
(
flag
==
1
)
ans
++
;
}
}
}
cout
<<
ans
;
return
0
;
}
```
data/1.算法初阶/3.蓝桥杯-递归/2.抽签/solution.md
浏览文件 @
25e421c2
...
...
@@ -9,34 +9,43 @@ C国最多可以派出2人。
那么最终派往W星的观察团会有多少种国别的不同组合呢?
**输入格式**
下面的程序解决了这个问题。
请你补全代码中空白的部分:
第一行N,以下N行代表N个国家最多可派出人数Ai。
**输出格式**
最多多少种派法ANS,ANS为一个整数。
**输出规模**
```
cpp
#include <bits/stdc++.h>
using
namespace
std
;
```
1<N<10000
1<AI<10000
```
**示例输入**
#define N 6
#define M 5
#define BUF 1024
```
6
4
2
2
1
1
3
```
**示例输出**
```
101
void
f
(
int
a
[],
int
k
,
int
m
,
char
b
[])
{
int
i
,
j
;
if
(
k
==
N
)
{
b
[
M
]
=
0
;
if
(
m
==
0
)
printf
(
"%s
\n
"
,
b
);
return
;
}
for
(
i
=
0
;
i
<=
a
[
k
];
i
++
)
{
for
(
j
=
0
;
j
<
i
;
j
++
)
b
[
M
-
m
+
j
]
=
k
+
'A'
;
__________________
}
}
int
main
()
{
int
a
[
N
]
=
{
4
,
2
,
2
,
1
,
1
,
3
};
char
b
[
BUF
];
f
(
a
,
0
,
M
,
b
);
return
0
;
}
```
...
...
@@ -45,45 +54,18 @@ C国最多可以派出2人。
### before
```
cpp
#include <iostream>
using
namespace
std
;
int
a
[
10000
],
N
,
i
,
ans
=
0
;
```
### after
```
cpp
int
main
()
{
cin
>>
N
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
cin
>>
a
[
i
];
}
findAns
(
a
,
0
,
0
);
cout
<<
ans
<<
endl
;
return
0
;
}
```
## 答案
```
cpp
void
findAns
(
int
a
[],
int
start
,
int
An
)
{
if
(
start
==
N
)
{
if
(
An
==
5
)
ans
++
;
return
;
}
for
(
i
=
0
;
i
<=
a
[
start
];
i
++
)
{
findAns
(
a
,
start
+
1
,
An
+
i
);
}
}
f
(
a
,
k
+
1
,
m
-
i
,
b
);
```
## 选项
...
...
@@ -91,56 +73,17 @@ void findAns(int a[], int start, int An)
### A
```
cpp
void
findAns
(
int
a
[],
int
start
,
int
An
)
{
if
(
start
==
N
)
{
if
(
An
==
5
)
ans
++
;
return
;
}
for
(
i
=
0
;
i
<=
a
[
start
];
i
++
)
{
findAns
(
a
,
start
+
1
,
An
);
}
}
f
(
a
,
k
,
m
-
i
,
b
);
```
### B
```
cpp
void
findAns
(
int
a
[],
int
start
,
int
An
)
{
if
(
start
==
N
)
{
if
(
An
==
5
)
ans
++
;
return
;
}
for
(
i
=
0
;
i
<=
a
[
start
];
i
++
)
{
findAns
(
a
,
start
,
An
+
i
);
}
}
f
(
a
,
k
-
1
,
m
-
i
,
b
);
```
### C
```
cpp
void
findAns
(
int
a
[],
int
start
,
int
An
)
{
if
(
start
==
N
)
{
if
(
An
==
5
)
ans
++
;
return
;
}
for
(
i
=
0
;
i
<=
a
[
start
];
i
++
)
{
findAns
(
a
,
start
,
An
+
1
);
}
}
f
(
a
,
k
+
1
,
m
+
i
,
b
);
```
data/1.算法初阶/3.蓝桥杯-递归/3.打印图形/solution.md
浏览文件 @
25e421c2
...
...
@@ -58,21 +58,31 @@ ran=6
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
```
小明开动脑筋,编写了如下的程序,实现该图形的打印。
## aop
### before
请你补全程序,实现该图形的打印。
```
cpp
#include <cstdio>
#include <bits/stdc++.h>
using
namespace
std
;
#define N 70
```
### after
```
cpp
void
f
(
char
a
[][
N
],
int
rank
,
int
row
,
int
col
)
{
if
(
rank
==
1
)
{
a
[
row
][
col
]
=
'*'
;
return
;
}
int
w
=
1
;
int
i
;
for
(
i
=
0
;
i
<
rank
-
1
;
i
++
)
w
*=
2
;
__________________
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
+
w
);
}
int
main
()
{
char
a
[
N
][
N
];
...
...
@@ -81,7 +91,6 @@ int main()
for
(
j
=
0
;
j
<
N
;
j
++
)
a
[
i
][
j
]
=
' '
;
f
(
a
,
4
,
0
,
0
);
for
(
i
=
0
;
i
<
N
;
i
++
)
{
...
...
@@ -92,28 +101,25 @@ int main()
return
0
;
}
```
## aop
### before
```
cpp
```
### after
```
cpp
```
## 答案
```
cpp
void
f
(
char
a
[][
N
],
int
rank
,
int
row
,
int
col
)
{
if
(
rank
==
1
)
{
a
[
row
][
col
]
=
'*'
;
return
;
}
int
w
=
1
;
int
i
;
for
(
i
=
0
;
i
<
rank
-
1
;
i
++
)
w
*=
2
;
f
(
a
,
rank
-
1
,
row
,
col
+
w
/
2
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
+
w
);
}
f
(
a
,
rank
-
1
,
row
,
col
+
w
/
2
);
```
## 选项
...
...
@@ -121,62 +127,17 @@ void f(char a[][N], int rank, int row, int col)
### A
```
cpp
void
f
(
char
a
[][
N
],
int
rank
,
int
row
,
int
col
)
{
if
(
rank
==
1
)
{
a
[
row
][
col
]
=
'*'
;
return
;
}
int
w
=
1
;
int
i
;
for
(
i
=
0
;
i
<
rank
;
i
++
)
w
*=
2
;
f
(
a
,
rank
-
1
,
row
,
col
+
w
/
2
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
+
w
);
}
f
(
a
,
rank
,
row
,
col
+
w
/
2
);
```
### B
```
cpp
void
f
(
char
a
[][
N
],
int
rank
,
int
row
,
int
col
)
{
if
(
rank
==
1
)
{
a
[
row
][
col
]
=
'*'
;
return
;
}
int
w
=
1
;
int
i
;
for
(
i
=
0
;
i
<
rank
-
1
;
i
++
)
w
*=
2
;
f
(
a
,
rank
+
1
,
row
,
col
+
w
/
2
);
f
(
a
,
rank
+
1
,
row
+
w
/
2
,
col
);
f
(
a
,
rank
+
1
,
row
+
w
/
2
,
col
+
w
);
}
f
(
a
,
rank
-
1
,
row
,
col
+
w
);
```
### C
```
cpp
void
f
(
char
a
[][
N
],
int
rank
,
int
row
,
int
col
)
{
if
(
rank
==
1
)
{
a
[
row
][
col
]
=
'*'
;
return
;
}
int
w
=
0
;
int
i
;
for
(
i
=
0
;
i
<
rank
-
1
;
i
++
)
w
*=
2
;
f
(
a
,
rank
-
1
,
row
,
col
+
w
/
2
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
);
f
(
a
,
rank
-
1
,
row
+
w
/
2
,
col
+
w
);
}
f
(
a
,
rank
+
1
,
row
,
col
+
w
/
2
);
```
data/1.算法初阶/3.蓝桥杯-递归/4.等差数列/solution.md
浏览文件 @
25e421c2
...
...
@@ -34,33 +34,20 @@
包含 2、6、4、10、20 的最短的等差数列是 2、4、6、8、10、12、14、16、18、20。
## aop
### before
下面的代码实现了这一功能,请你补全代码中的空白处:
```
cpp
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using
namespace
std
;
const
int
N
=
1e5
+
10
;
int
a
[
N
];
int
gcd
(
int
a
,
int
b
)
int
gcd
(
int
a
,
int
b
)
{
return
b
?
gcd
(
b
,
a
%
b
)
:
a
;
__________________
}
```
### after
```
cpp
```
## 答案
```
cpp
int
main
()
{
int
n
;
...
...
@@ -68,95 +55,56 @@ int main()
for
(
int
i
=
0
;
i
<
n
;
i
++
)
cin
>>
a
[
i
];
sort
(
a
,
a
+
n
);
sort
(
a
,
a
+
n
);
int
d
=
0
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
d
=
gcd
(
d
,
a
[
i
]
-
a
[
0
]);
d
=
gcd
(
d
,
a
[
i
]
-
a
[
0
]);
if
(
d
)
cout
<<
(
a
[
n
-
1
]
-
a
[
0
])
/
d
+
1
;
cout
<<
(
a
[
n
-
1
]
-
a
[
0
])
/
d
+
1
;
else
cout
<<
n
;
return
0
;
}
```
## 选项
## aop
###
A
###
before
```
cpp
int
main
()
{
int
n
;
cin
>>
n
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
cin
>>
a
[
i
];
sort
(
a
,
a
+
n
);
int
d
=
0
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
d
=
gcd
(
d
,
a
[
i
]
-
a
[
0
]);
```
### after
if
(
d
)
cout
<<
(
a
[
n
]
-
a
[
0
])
/
d
+
1
;
else
cout
<<
n
;
```
cpp
return
0
;
}
```
##
# B
##
答案
```
cpp
int
main
()
{
int
n
;
cin
>>
n
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
cin
>>
a
[
i
];
return
b
?
gcd
(
b
,
a
%
b
)
:
a
;
```
## 选项
sort
(
a
,
a
+
n
);
int
d
=
0
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
d
=
gcd
(
d
,
a
[
i
]
-
a
[
0
]);
if
(
d
)
cout
<<
(
a
[
n
-
1
]
-
a
[
0
])
/
d
;
else
cout
<<
n
;
### A
return
0
;
}
```
cpp
return
b
?
gcd
(
b
,
a
)
:
a
;
```
###
C
###
B
```
cpp
int
main
()
{
int
n
;
cin
>>
n
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
cin
>>
a
[
i
];
sort
(
a
,
a
+
n
);
int
d
=
0
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
d
=
gcd
(
d
,
a
[
i
]
-
a
[
0
]);
return
b
?
gcd
(
b
,
a
/
b
)
:
a
;
```
if
(
d
)
cout
<<
(
a
[
n
+
1
]
-
a
[
0
])
/
d
+
1
;
else
cout
<<
n
;
### C
return
0
;
}
```
cpp
return
b
?
gcd
(
b
,
a
+
b
)
:
a
;
```
data/1.算法初阶/4.蓝桥杯-堆栈队列链表/1.堆的计数/solution.md
浏览文件 @
25e421c2
...
...
@@ -58,15 +58,12 @@
峰值内存消耗(含虚拟机) < 256M
CPU消耗 < 1000ms
## aop
### before
下面的代码实现了这一功能,请你补全空白处缺失的代码:
```
cpp
#include <bits/stdc++.h>
using
namespace
std
;
typedef
long
long
ll
;
const
int
maxn
=
100000
;
ll
s
[
maxn
+
10
],
dp
[
maxn
+
10
],
inv
[
maxn
+
10
],
f
[
maxn
+
10
];
...
...
@@ -90,16 +87,7 @@ ll C(ll n, ll m)
{
return
(
f
[
n
]
*
inv
[
f
[
m
]])
%
mod
*
inv
[
f
[
n
-
m
]]
%
mod
;
}
```
### after
```
cpp
```
## 答案
```
cpp
int
main
()
{
cin
>>
n
;
...
...
@@ -121,108 +109,49 @@ int main()
{
if
(
i
*
2
+
1
<=
n
)
{
dp
[
i
]
=
(
C
(
s
[
i
]
-
1
,
s
[
i
*
2
+
1
])
*
dp
[
i
*
2
+
1
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
__________________
}
}
cout
<<
dp
[
1
]
<<
endl
;
return
0
;
}
```
## aop
### before
```
cpp
```
### after
```
cpp
```
## 答案
```
cpp
dp
[
i
]
=
(
C
(
s
[
i
]
-
1
,
s
[
i
*
2
+
1
])
*
dp
[
i
*
2
+
1
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
```
## 选项
### A
```
cpp
int
main
()
{
cin
>>
n
;
f
[
0
]
=
1
;
for
(
int
i
=
1
;
i
<=
maxn
;
i
++
)
{
f
[
i
]
=
(
f
[
i
-
1
]
*
i
)
%
mod
;
inv
[
i
]
=
qPow
(
i
,
mod
-
2
);
}
for
(
int
i
=
n
;
i
>=
1
;
i
--
)
{
s
[
i
]
=
(
s
[
i
*
2
+
1
]
<=
n
?
s
[
i
*
2
+
1
]
:
0
)
+
(
s
[
i
*
2
]
<=
n
?
s
[
i
*
2
]
:
0
)
+
1
;
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
dp
[
i
]
=
1
;
}
for
(
int
i
=
n
;
i
>=
1
;
i
--
)
{
if
(
i
*
2
+
1
<=
n
)
{
dp
[
i
]
=
(
C
(
s
[
i
]
-
1
,
s
[
i
*
2
-
1
])
*
dp
[
i
*
2
+
1
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
}
}
cout
<<
dp
[
1
]
<<
endl
;
return
0
;
}
dp
[
i
]
=
(
C
(
s
[
i
],
s
[
i
*
2
+
1
])
*
dp
[
i
*
2
+
1
])
%
mod
*
dp
[
i
*
2
+
1
]
%
mod
;
```
### B
```
cpp
int
main
()
{
cin
>>
n
;
f
[
0
]
=
1
;
for
(
int
i
=
1
;
i
<=
maxn
;
i
++
)
{
f
[
i
]
=
(
f
[
i
-
1
]
*
i
)
%
mod
;
inv
[
i
]
=
qPow
(
i
,
mod
-
2
);
}
for
(
int
i
=
n
;
i
>=
1
;
i
--
)
{
s
[
i
]
=
(
s
[
i
*
2
+
1
]
<=
n
?
s
[
i
*
2
+
1
]
:
0
)
+
(
s
[
i
*
2
]
<=
n
?
s
[
i
*
2
]
:
0
)
+
1
;
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
dp
[
i
]
=
1
;
}
for
(
int
i
=
n
;
i
>=
1
;
i
--
)
{
if
(
i
*
2
+
1
<=
n
)
{
dp
[
i
]
=
(
C
(
s
[
i
]
-
1
,
s
[
i
*
2
-
1
])
*
dp
[
i
*
2
-
1
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
}
}
cout
<<
dp
[
1
]
<<
endl
;
return
0
;
}
dp
[
i
]
=
(
C
(
s
[
i
]
-
1
,
s
[
i
*
2
])
*
dp
[
i
*
2
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
```
### C
```
cpp
int
main
()
{
cin
>>
n
;
f
[
0
]
=
1
;
for
(
int
i
=
1
;
i
<=
maxn
;
i
++
)
{
f
[
i
]
=
(
f
[
i
-
1
]
*
i
)
%
mod
;
inv
[
i
]
=
qPow
(
i
,
mod
-
2
);
}
for
(
int
i
=
n
;
i
>=
1
;
i
--
)
{
s
[
i
]
=
(
s
[
i
*
2
+
1
]
<=
n
?
s
[
i
*
2
+
1
]
:
0
)
+
(
s
[
i
*
2
]
<=
n
?
s
[
i
*
2
]
:
0
)
+
1
;
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
dp
[
i
]
=
1
;
}
for
(
int
i
=
n
;
i
>=
1
;
i
--
)
{
if
(
i
*
2
+
1
<=
n
)
{
dp
[
i
]
=
(
C
(
s
[
i
],
s
[
i
*
2
])
*
dp
[
i
*
2
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
}
}
cout
<<
dp
[
1
]
<<
endl
;
return
0
;
}
dp
[
i
]
=
(
C
(
s
[
i
]
+
1
,
s
[
i
*
2
+
1
])
*
dp
[
i
*
2
+
1
])
%
mod
*
dp
[
i
*
2
]
%
mod
;
```
data/1.算法初阶/6.蓝桥杯-模拟/1.方格填数/solution.md
浏览文件 @
25e421c2
...
...
@@ -12,56 +12,18 @@
### before
```
cpp
#include <iostream>
#include <algorithm>
#include <cmath>
using
namespace
std
;
int
a
[
10
];
int
ans
;
```
### after
```
cpp
int
main
()
{
for
(
int
i
=
0
;
i
<=
9
;
i
++
)
a
[
i
]
=
i
;
do
{
if
(
check
())
ans
++
;
}
while
(
next_permutation
(
a
,
a
+
10
));
cout
<<
ans
;
return
0
;
}
```
## 答案
```
cpp
bool
check
()
{
if
(
abs
(
a
[
0
]
-
a
[
1
])
==
1
||
abs
(
a
[
0
]
-
a
[
3
])
==
1
||
abs
(
a
[
0
]
-
a
[
4
])
==
1
||
abs
(
a
[
0
]
-
a
[
5
])
==
1
)
return
false
;
if
(
abs
(
a
[
1
]
-
a
[
2
])
==
1
||
abs
(
a
[
1
]
-
a
[
4
])
==
1
||
abs
(
a
[
1
]
-
a
[
5
])
==
1
||
abs
(
a
[
1
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
2
]
-
a
[
5
])
==
1
||
abs
(
a
[
2
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
3
]
-
a
[
4
])
==
1
||
abs
(
a
[
3
]
-
a
[
7
])
==
1
||
abs
(
a
[
3
]
-
a
[
8
])
==
1
)
return
false
;
if
(
abs
(
a
[
4
]
-
a
[
5
])
==
1
||
abs
(
a
[
4
]
-
a
[
7
])
==
1
||
abs
(
a
[
4
]
-
a
[
8
])
==
1
||
abs
(
a
[
4
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
5
]
-
a
[
6
])
==
1
||
abs
(
a
[
5
]
-
a
[
8
])
==
1
||
abs
(
a
[
5
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
6
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
7
]
-
a
[
8
])
==
1
||
abs
(
a
[
8
]
-
a
[
9
])
==
1
)
return
false
;
return
true
;
}
1580
```
## 选项
...
...
@@ -69,76 +31,17 @@ bool check()
### A
```
cpp
bool
check
()
{
if
(
abs
(
a
[
0
]
-
a
[
1
])
==
1
||
abs
(
a
[
0
]
-
a
[
3
])
==
1
||
abs
(
a
[
0
]
-
a
[
4
])
==
1
||
abs
(
a
[
0
]
-
a
[
5
])
==
1
)
return
false
;
if
(
abs
(
a
[
1
]
-
a
[
2
])
==
1
||
abs
(
a
[
1
]
-
a
[
4
])
==
1
||
abs
(
a
[
1
]
-
a
[
5
])
==
1
||
abs
(
a
[
1
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
2
]
-
a
[
5
])
==
1
||
abs
(
a
[
2
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
3
]
-
a
[
4
])
==
1
||
abs
(
a
[
3
]
-
a
[
7
])
==
1
||
abs
(
a
[
3
]
-
a
[
8
])
==
1
)
return
false
;
if
(
abs
(
a
[
4
]
-
a
[
5
])
==
1
||
abs
(
a
[
4
]
-
a
[
7
])
==
1
||
abs
(
a
[
4
]
-
a
[
8
])
==
1
||
abs
(
a
[
4
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
5
]
-
a
[
6
])
==
1
||
abs
(
a
[
5
]
-
a
[
8
])
==
1
||
abs
(
a
[
5
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
6
]
-
a
[
7
])
==
1
)
return
false
;
if
(
abs
(
a
[
7
]
-
a
[
8
])
==
1
||
abs
(
a
[
8
]
-
a
[
9
])
==
1
)
return
false
;
return
true
;
}
1579
```
### B
```
cpp
bool
check
()
{
if
(
abs
(
a
[
0
]
-
a
[
1
])
==
1
||
abs
(
a
[
0
]
-
a
[
3
])
==
1
||
abs
(
a
[
0
]
-
a
[
4
])
==
1
||
abs
(
a
[
0
]
-
a
[
5
])
==
1
)
return
false
;
if
(
abs
(
a
[
1
]
-
a
[
2
])
==
1
||
abs
(
a
[
1
]
-
a
[
4
])
==
1
||
abs
(
a
[
1
]
-
a
[
5
])
==
1
||
abs
(
a
[
1
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
2
]
-
a
[
5
])
==
1
||
abs
(
a
[
2
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
3
]
-
a
[
4
])
==
1
||
abs
(
a
[
3
]
-
a
[
7
])
==
1
||
abs
(
a
[
3
]
-
a
[
8
])
==
1
)
return
false
;
if
(
abs
(
a
[
4
]
-
a
[
5
])
==
1
||
abs
(
a
[
4
]
-
a
[
7
])
==
1
||
abs
(
a
[
4
]
-
a
[
8
])
==
1
||
abs
(
a
[
4
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
5
]
-
a
[
6
])
==
1
||
abs
(
a
[
5
]
-
a
[
8
])
==
1
||
abs
(
a
[
5
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
6
]
-
a
[
7
])
==
1
)
return
false
;
if
(
abs
(
a
[
7
]
-
a
[
8
])
==
1
)
return
false
;
if
(
abs
(
a
[
8
]
-
a
[
9
])
==
1
)
return
false
;
return
true
;
}
1582
```
### C
```
cpp
bool
check
()
{
if
(
abs
(
a
[
0
]
-
a
[
1
])
==
1
||
abs
(
a
[
0
]
-
a
[
3
])
==
1
||
abs
(
a
[
0
]
-
a
[
4
])
==
1
||
abs
(
a
[
0
]
-
a
[
5
])
==
1
)
return
false
;
if
(
abs
(
a
[
1
]
-
a
[
2
])
==
1
||
abs
(
a
[
1
]
-
a
[
4
])
==
1
||
abs
(
a
[
1
]
-
a
[
5
])
==
1
||
abs
(
a
[
1
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
2
]
-
a
[
5
])
==
1
||
abs
(
a
[
2
]
-
a
[
6
])
==
1
)
return
false
;
if
(
abs
(
a
[
3
]
-
a
[
4
])
==
1
||
abs
(
a
[
3
]
-
a
[
7
])
==
1
||
abs
(
a
[
3
]
-
a
[
8
])
==
1
)
return
false
;
if
(
abs
(
a
[
4
]
-
a
[
5
])
==
1
||
abs
(
a
[
4
]
-
a
[
7
])
==
1
||
abs
(
a
[
4
]
-
a
[
8
])
==
1
||
abs
(
a
[
4
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
5
]
-
a
[
6
])
==
1
||
abs
(
a
[
5
]
-
a
[
8
])
==
1
||
abs
(
a
[
5
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
6
]
-
a
[
9
])
==
1
)
return
false
;
if
(
abs
(
a
[
7
]
-
a
[
8
])
==
1
)
return
false
;
return
true
;
}
1581
```
data/1.算法初阶/6.蓝桥杯-模拟/10.放棋子/solution.md
浏览文件 @
25e421c2
# 放棋子
今有6×6的棋盘,其中某些格子已预放了棋子。现在要再放上去一些,使得每行每列都正好有3颗棋子。我们希望推算出所有可能的放法,下面的代码就实现了这个功能。初始数组中,“1”表示放有棋子,“0”表示空白。
今有6×6的棋盘,其中某些格子已预放了棋子。现在要再放上去一些,使得每行每列都正好有3颗棋子。最多有多少种放法?
![](
https://img-blog.csdn.net/20170302185510449
)
## aop
...
...
@@ -8,130 +9,18 @@
### before
```
cpp
#include <iostream>
#include <cstdio>
int
N
=
0
;
bool
CheckStoneNum
(
int
x
[][
6
])
{
for
(
int
k
=
0
;
k
<
6
;
++
k
)
{
int
NumRow
=
0
,
NumCol
=
0
;
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
if
(
x
[
k
][
i
])
NumRow
++
;
if
(
x
[
i
][
k
])
NumCol
++
;
}
if
(
NumRow
!=
3
||
NumCol
!=
3
)
return
false
;
}
return
true
;
}
int
GetRowStoneNum
(
int
x
[][
6
],
int
r
)
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
if
(
x
[
r
][
i
])
sum
++
;
}
return
sum
;
}
int
GetColStoneNum
(
int
x
[][
6
],
int
c
)
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
if
(
x
[
i
][
c
])
sum
++
;
}
return
sum
;
}
void
show
(
int
x
[][
6
])
{
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
for
(
int
j
=
0
;
j
<
6
;
++
j
)
{
printf
(
"%2d"
,
x
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
}
void
f
(
int
x
[][
6
],
int
r
,
int
c
);
void
GoNext
(
int
x
[][
6
],
int
r
,
int
c
)
{
if
(
c
<
6
)
{
f
(
x
,
r
,
c
+
1
);
}
else
{
f
(
x
,
r
+
1
,
0
);
}
}
```
### after
```
cpp
int
main
()
{
int
x
[
6
][
6
]
=
{
{
1
,
0
,
0
,
0
,
0
,
0
},
{
0
,
0
,
1
,
0
,
1
,
0
},
{
0
,
0
,
1
,
1
,
0
,
1
},
{
0
,
1
,
0
,
0
,
1
,
0
},
{
0
,
0
,
0
,
1
,
0
,
0
},
{
1
,
0
,
1
,
0
,
0
,
1
},
};
f
(
x
,
0
,
0
);
printf
(
"%d
\n
"
,
N
);
return
0
;
}
```
## 答案
```
cpp
void
f
(
int
x
[][
6
],
int
r
,
int
c
)
{
if
(
r
==
6
)
{
if
(
CheckStoneNum
(
x
))
{
N
++
;
show
(
x
);
}
return
;
}
if
(
x
[
r
][
c
])
{
GoNext
(
x
,
r
,
c
);
return
;
}
int
rr
=
GetRowStoneNum
(
x
,
r
);
int
cc
=
GetColStoneNum
(
x
,
c
);
if
(
cc
>=
3
)
{
GoNext
(
x
,
r
,
c
);
}
else
if
(
rr
>=
3
)
{
f
(
x
,
r
+
1
,
0
);
}
else
{
x
[
r
][
c
]
=
1
;
GoNext
(
x
,
r
,
c
);
x
[
r
][
c
]
=
0
;
if
(
!
(
3
-
rr
>=
6
-
c
||
3
-
cc
>=
6
-
r
))
{
GoNext
(
x
,
r
,
c
);
}
}
}
16
```
## 选项
...
...
@@ -139,116 +28,17 @@ void f(int x[][6], int r, int c)
### A
```
cpp
void
f
(
int
x
[][
6
],
int
r
,
int
c
)
{
if
(
r
==
6
)
{
if
(
CheckStoneNum
(
x
))
{
N
++
;
show
(
x
);
}
return
;
}
if
(
x
[
r
][
c
])
{
GoNext
(
x
,
r
,
c
);
return
;
}
int
rr
=
GetRowStoneNum
(
x
,
r
);
int
cc
=
GetColStoneNum
(
x
,
c
);
if
(
cc
>=
3
)
{
GoNext
(
x
,
r
,
c
);
}
else
if
(
rr
>=
3
)
{
f
(
x
,
r
+
1
,
0
);
}
else
{
x
[
r
][
c
]
=
1
;
GoNext
(
x
,
r
,
c
);
x
[
r
][
c
]
=
0
;
}
}
17
```
### B
```
cpp
void
f
(
int
x
[][
6
],
int
r
,
int
c
)
{
if
(
r
==
6
)
{
if
(
CheckStoneNum
(
x
))
{
N
++
;
show
(
x
);
}
return
;
}
if
(
x
[
r
][
c
])
{
GoNext
(
x
,
r
,
c
);
return
;
}
int
rr
=
GetRowStoneNum
(
x
,
r
);
int
cc
=
GetColStoneNum
(
x
,
c
);
if
(
cc
>=
3
)
{
GoNext
(
x
,
r
,
c
);
}
else
if
(
rr
>=
3
)
{
f
(
x
,
r
+
1
,
0
);
}
else
{
if
(
!
(
3
-
rr
>=
6
-
c
||
3
-
cc
>=
6
-
r
))
{
GoNext
(
x
,
r
,
c
);
}
}
}
18
```
### C
```
cpp
void
f
(
int
x
[][
6
],
int
r
,
int
c
)
{
if
(
r
==
6
)
{
if
(
CheckStoneNum
(
x
))
{
N
++
;
show
(
x
);
}
return
;
}
if
(
x
[
r
][
c
])
{
GoNext
(
x
,
r
,
c
);
return
;
}
int
rr
=
GetRowStoneNum
(
x
,
r
);
int
cc
=
GetColStoneNum
(
x
,
c
);
if
(
cc
>=
3
)
{
GoNext
(
x
,
r
,
c
);
}
else
if
(
rr
>=
3
)
{
f
(
x
,
r
+
1
,
0
);
}
else
{
x
[
r
][
c
]
=
0
;
if
(
!
(
3
-
rr
>=
6
-
c
||
3
-
cc
>=
6
-
r
))
{
GoNext
(
x
,
r
,
c
);
}
}
}
19
```
data/1.算法初阶/6.蓝桥杯-模拟/2.等腰三角形/solution.md
浏览文件 @
25e421c2
...
...
@@ -41,16 +41,14 @@
![](
https://img-blog.csdnimg.cn/20190203175213126.png
)
以下代码不能实现该功能的一项是?
## aop
### before
```
cpp
#include <bits/stdc++.h>
using
namespace
std
;
string
str
;
stringstream
ss
;
```
### after
...
...
@@ -61,62 +59,55 @@ stringstream ss;
## 答案
```
cpp
string
s
;
void
init
()
{
for
(
int
i
=
1
;
i
<=
1000
;
i
++
)
{
string
str
=
""
;
int
x
=
i
;
while
(
x
!=
0
)
{
str
+=
(
char
)(
x
%
10
+
'0'
);
x
=
x
/
10
;
}
reverse
(
str
.
begin
(),
str
.
end
());
s
+=
str
;
}
}
int
main
()
{
init
();
int
n
;
cin
>>
n
;
int
x
=
2
*
n
-
1
;
for
(
int
i
=
1
;
i
<=
1500
;
i
++
)
{
string
str1
;
ss
<<
i
;
ss
>>
str1
;
str
+=
str1
;
ss
.
clear
();
}
int
length
=
4
*
n
-
4
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
if
(
i
!=
n
&&
i
!=
1
)
{
for
(
int
j
=
1
;
j
<=
n
+
i
-
1
;
j
++
)
while
(
cin
>>
n
)
{
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
for
(
int
j
=
1
;
j
<=
n
-
i
;
j
++
)
{
if
(
j
==
n
-
i
+
1
)
{
cout
<<
str
[
i
-
1
];
}
else
if
(
j
==
2
*
n
-
(
n
-
i
+
1
))
{
cout
<<
str
[
4
*
n
-
4
-
(
i
-
1
)]
<<
endl
;
}
else
{
cout
<<
'.'
;
}
cout
<<
"."
;
}
}
else
if
(
i
==
1
)
{
for
(
int
x
=
1
;
x
<=
n
;
x
++
)
{
if
(
x
==
n
)
{
cout
<<
'1'
<<
endl
;
}
else
cout
<<
s
[
i
-
1
];
if
(
i
!=
1
)
{
for
(
int
j
=
1
;
j
<
i
-
1
;
j
++
)
{
cout
<<
'.'
;
cout
<<
"."
;
}
cout
<<
s
[
4
*
(
n
-
1
)
+
1
-
i
];
}
cout
<<
endl
;
}
else
for
(
int
i
=
0
;
i
<
2
*
(
n
-
1
)
+
1
;
i
++
)
{
for
(
int
m
=
1
;
m
<=
2
*
n
-
1
;
m
++
)
{
cout
<<
str
[
n
+
(
m
-
2
)];
}
cout
<<
s
[
n
-
1
+
i
];
}
cout
<<
endl
;
}
return
0
;
}
```
...
...
@@ -129,59 +120,145 @@ int main()
int
main
()
{
int
n
;
cin
>>
n
;
int
x
=
2
*
n
-
1
;
for
(
int
i
=
1
;
i
<=
1500
;
i
++
)
{
string
str1
;
ss
<<
i
;
ss
>>
str1
;
str
+=
str1
;
ss
.
clear
();
}
int
length
=
4
*
n
-
4
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
if
(
i
!=
n
&&
i
!=
1
)
{
for
(
int
j
=
1
;
j
<=
n
+
i
-
1
;
j
++
)
scanf
(
"%d"
,
&
n
);
int
s
=
0
;
int
q
=
0
,
w
=
0
,
count
=
1
;
int
arr
[
300
][
600
];
int
p
=
n
-
1
,
r
=
n
;
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
for
(
int
j
=
0
;
j
<
r
;
j
++
)
{
if
(
j
==
p
)
{
if
(
j
==
n
-
i
+
1
)
{
cout
<<
str
[
i
-
1
];
if
(
s
==
2
)
{
s
=
1
;
arr
[
i
][
j
]
=
q
+
'0'
;
}
else
if
(
j
==
2
*
n
-
(
n
-
i
+
1
))
{
cout
<<
str
[
4
*
n
-
4
-
i
]
<<
endl
;
else
if
(
s
==
1
)
{
s
=
0
;
arr
[
i
][
j
]
=
w
+
'0'
;
}
else
{
cout
<<
'.'
;
arr
[
i
][
j
]
=
count
+
'0'
;
count
++
;
if
(
count
==
10
)
{
count
=
0
;
w
++
;
if
(
w
==
10
)
{
w
=
0
;
q
++
;
}
}
if
(
w
!=
0
)
{
s
=
1
;
}
if
(
q
!=
0
)
{
s
=
2
;
}
}
}
else
{
arr
[
i
][
j
]
=
'.'
;
}
}
else
if
(
i
==
1
)
p
--
;
r
++
;
}
for
(
int
j
=
0
;
j
<
r
;
j
++
)
{
if
(
s
==
2
)
{
for
(
int
x
=
1
;
x
<=
n
;
x
++
)
{
if
(
x
==
n
)
{
cout
<<
'1'
<<
endl
;
}
else
s
=
1
;
arr
[
n
-
1
][
j
]
=
q
+
'0'
;
}
else
if
(
s
==
1
)
{
s
=
0
;
arr
[
n
-
1
][
j
]
=
w
+
'0'
;
}
else
{
arr
[
n
-
1
][
j
]
=
count
+
'0'
;
count
++
;
if
(
count
==
10
)
{
count
=
0
;
w
++
;
if
(
w
==
10
)
{
cout
<<
'.'
;
w
=
0
;
q
++
;
}
}
if
(
w
!=
0
)
{
s
=
1
;
}
if
(
q
!=
0
)
{
s
=
2
;
}
}
}
r
--
;
for
(
int
i
=
n
-
2
;
i
>
0
;
i
--
)
{
r
--
;
if
(
s
==
2
)
{
s
=
1
;
arr
[
i
][
r
]
=
q
+
'0'
;
}
else
if
(
s
==
1
)
{
s
=
0
;
arr
[
i
][
r
]
=
w
+
'0'
;
}
else
{
for
(
int
m
=
1
;
m
<=
2
*
n
-
1
;
m
++
)
{
cout
<<
str
[
n
+
(
m
-
2
)];
arr
[
i
][
r
]
=
count
+
'0'
;
count
++
;
if
(
count
==
10
)
{
count
=
0
;
w
++
;
if
(
w
==
10
)
{
w
=
0
;
q
++
;
}
}
if
(
w
!=
0
)
{
s
=
1
;
}
if
(
q
!=
0
)
{
s
=
2
;
}
}
}
r
=
n
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
for
(
int
j
=
0
;
j
<
r
;
j
++
)
{
printf
(
"%c"
,
arr
[
i
][
j
]);
}
printf
(
"
\n
"
);
r
++
;
}
return
0
;
}
```
...
...
@@ -189,61 +266,72 @@ int main()
### B
```
cpp
int
a
[
3005
],
n
;
char
m
[
1300
][
1300
];
void
init
()
{
int
cnt
=
1
,
p
=
1
;
while
(
1
)
{
if
(
cnt
>=
3000
)
break
;
if
(
p
<
10
)
a
[
cnt
++
]
=
p
;
else
if
(
p
<
100
&&
p
>=
10
)
{
a
[
cnt
++
]
=
p
/
10
;
a
[
cnt
++
]
=
p
%
10
;
}
else
if
(
p
>=
100
&&
p
<
1000
)
{
a
[
cnt
++
]
=
p
/
100
;
a
[
cnt
++
]
=
p
/
10
%
10
;
a
[
cnt
++
]
=
p
%
10
;
}
else
if
(
p
>=
1000
&&
p
<
9999
)
{
a
[
cnt
++
]
=
p
/
1000
;
a
[
cnt
++
]
=
p
/
100
%
10
;
a
[
cnt
++
]
=
p
/
10
%
10
;
a
[
cnt
++
]
=
p
%
10
;
}
p
++
;
}
}
int
main
()
{
in
t
n
;
in
it
()
;
cin
>>
n
;
int
x
=
2
*
n
-
1
;
for
(
int
i
=
1
;
i
<=
1500
;
i
++
)
{
string
str1
;
ss
<<
i
;
ss
>>
str1
;
str
+=
str1
;
ss
.
clear
();
int
cnt
=
1
;
for
(
int
i
=
1
;
i
<=
n
-
1
;
i
++
)
{
for
(
int
j
=
n
;
j
>=
1
;
j
--
)
if
(
i
+
j
==
n
+
1
)
m
[
i
][
j
]
=
a
[
cnt
++
]
+
'0'
;
else
m
[
i
][
j
]
=
'.'
;
}
int
length
=
4
*
n
-
4
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
if
(
i
!=
n
&&
i
!=
1
)
{
for
(
int
j
=
1
;
j
<=
n
+
i
-
1
;
j
++
)
{
if
(
j
==
n
-
i
+
1
)
{
cout
<<
str
[
i
-
1
];
}
else
if
(
j
==
2
*
n
-
(
n
-
i
+
1
))
{
cout
<<
str
[
4
*
n
-
4
-
(
i
+
1
)]
<<
endl
;
}
else
{
cout
<<
'.'
;
}
}
}
else
if
(
i
==
1
)
for
(
int
i
=
1
;
i
<=
n
*
2
-
1
;
i
++
)
m
[
n
][
i
]
=
a
[
cnt
++
]
+
'0'
;
for
(
int
i
=
n
-
1
;
i
>=
2
;
i
--
)
{
for
(
int
j
=
2
*
n
-
2
;
j
>=
n
;
j
--
)
{
for
(
int
x
=
1
;
x
<=
n
;
x
++
)
{
if
(
x
==
n
)
{
cout
<<
'1'
<<
endl
;
}
else
{
cout
<<
'.'
;
}
}
if
(
j
-
i
==
n
-
1
)
m
[
i
][
j
]
=
a
[
cnt
++
]
+
'0'
;
else
m
[
i
][
j
]
=
'.'
;
}
else
}
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
for
(
int
j
=
1
;
j
<=
n
+
i
-
1
;
j
++
)
{
for
(
int
m
=
1
;
m
<=
2
*
n
-
1
;
m
++
)
{
cout
<<
str
[
n
+
(
m
-
2
)];
}
cout
<<
m
[
i
][
j
];
}
cout
<<
endl
;
}
return
0
;
}
...
...
@@ -252,33 +340,36 @@ int main()
### C
```
cpp
string
str
;
stringstream
ss
;
int
main
()
{
int
n
;
cin
>>
n
;
int
x
=
2
*
n
-
1
;
for
(
int
i
=
1
;
i
<=
1500
;
i
++
)
{
{
string
str1
;
ss
<<
i
;
ss
>>
str1
;
str
+=
str1
;
ss
.
clear
();
}
int
length
=
4
*
n
-
4
;
int
length
=
4
*
n
-
4
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
{
if
(
i
!=
n
&&
i
!=
1
)
{
{
for
(
int
j
=
1
;
j
<=
n
+
i
-
1
;
j
++
)
{
if
(
j
==
n
-
i
+
1
)
{
{
cout
<<
str
[
i
-
1
];
}
else
if
(
j
==
2
*
n
-
(
n
-
i
+
1
))
{
cout
<<
str
[
4
*
n
-
4
+
i
]
<<
endl
;
{
cout
<<
str
[
4
*
n
-
4
-
(
i
-
1
)]
<<
endl
;
}
else
{
...
...
@@ -289,7 +380,7 @@ int main()
else
if
(
i
==
1
)
{
for
(
int
x
=
1
;
x
<=
n
;
x
++
)
{
{
if
(
x
==
n
)
{
cout
<<
'1'
<<
endl
;
...
...
@@ -303,7 +394,7 @@ int main()
else
{
for
(
int
m
=
1
;
m
<=
2
*
n
-
1
;
m
++
)
{
{
cout
<<
str
[
n
+
(
m
-
2
)];
}
}
...
...
data/1.算法初阶/6.蓝桥杯-模拟/3.承压计算/solution.md
浏览文件 @
25e421c2
...
...
@@ -52,20 +52,48 @@ X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
请你推算出:读数最大的电子秤的示数为多少?
## aop
### before
以下的代码可以计算出点子称的示数,请你补全它:
```
cpp
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <bits/stdc++.h>
using
namespace
std
;
typedef
long
long
ll
;
const
ll
maxn
=
1e6
+
50
;
double
a
[
1050
][
1050
];
int
main
()
{
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
scanf
(
"%lf"
,
&
a
[
i
][
j
]);
}
}
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
a
[
i
+
1
][
j
]
+=
(
0.5
*
a
[
i
][
j
]);
__________________
}
}
double
minn
=
1000000000
,
maxx
=
-
1
;
for
(
ll
i
=
1
;
i
<=
30
;
i
++
)
{
maxx
=
max
(
maxx
,
a
[
30
][
i
]);
minn
=
min
(
minn
,
a
[
30
][
i
]);
}
printf
(
"%lf
\n
"
,
maxx
*
2086458231
/
minn
);
}
```
## aop
### before
```
cpp
```
### after
...
...
@@ -76,32 +104,7 @@ double a[1050][1050];
## 答案
```
cpp
int
main
()
{
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
scanf
(
"%lf"
,
&
a
[
i
][
j
]);
}
}
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
a
[
i
+
1
][
j
]
+=
(
0.5
*
a
[
i
][
j
]);
a
[
i
+
1
][
j
+
1
]
+=
(
0.5
*
a
[
i
][
j
]);
}
}
double
minn
=
1000000000
,
maxx
=
-
1
;
for
(
ll
i
=
1
;
i
<=
30
;
i
++
)
{
maxx
=
max
(
maxx
,
a
[
30
][
i
]);
minn
=
min
(
minn
,
a
[
30
][
i
]);
printf
(
"%lf
\n
"
,
a
[
30
][
i
]);
}
printf
(
"%lf
\n
"
,
maxx
*
2086458231
/
minn
);
}
a
[
i
+
1
][
j
+
1
]
+=
(
0.5
*
a
[
i
][
j
]);
```
## 选项
...
...
@@ -109,94 +112,17 @@ int main()
### A
```
cpp
int
main
()
{
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
scanf
(
"%lf"
,
&
a
[
i
][
j
]);
}
}
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
a
[
i
+
1
][
j
]
+=
(
0.5
*
a
[
i
][
j
]);
a
[
i
+
1
][
j
+
1
]
+=
(
0.5
*
a
[
i
][
j
]);
}
}
double
minn
=
1000000000
,
maxx
=
-
1
;
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
maxx
=
max
(
maxx
,
a
[
30
][
i
]);
minn
=
min
(
minn
,
a
[
30
][
i
]);
printf
(
"%lf
\n
"
,
a
[
30
][
i
]);
}
printf
(
"%lf
\n
"
,
maxx
*
2086458231
/
minn
);
}
a
[
i
+
1
][
j
]
+=
(
0.5
*
a
[
i
][
j
]);
```
### B
```
cpp
int
main
()
{
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
scanf
(
"%lf"
,
&
a
[
i
][
j
]);
}
}
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
a
[
i
+
1
][
j
]
=
(
0.5
*
a
[
i
][
j
]);
a
[
i
+
1
][
j
+
1
]
=
(
0.5
*
a
[
i
][
j
]);
}
}
double
minn
=
1000000000
,
maxx
=
-
1
;
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
maxx
=
max
(
maxx
,
a
[
30
][
i
]);
minn
=
min
(
minn
,
a
[
30
][
i
]);
printf
(
"%lf
\n
"
,
a
[
30
][
i
]);
}
printf
(
"%lf
\n
"
,
maxx
*
2086458231
/
minn
);
}
a
[
i
][
j
+
1
]
+=
(
0.5
*
a
[
i
][
j
]);
```
### C
```
cpp
int
main
()
{
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
scanf
(
"%lf"
,
&
a
[
i
][
j
]);
}
}
for
(
ll
i
=
1
;
i
<=
29
;
i
++
)
{
for
(
ll
j
=
1
;
j
<=
i
;
j
++
)
{
a
[
i
+
1
][
j
]
+=
(
0.5
*
a
[
i
][
j
]);
a
[
i
][
j
+
1
]
+=
(
0.5
*
a
[
i
][
j
]);
}
}
double
minn
=
1000000000
,
maxx
=
-
1
;
for
(
ll
i
=
1
;
i
<=
30
;
i
++
)
{
maxx
=
max
(
maxx
,
a
[
30
][
i
]);
minn
=
min
(
minn
,
a
[
30
][
i
]);
printf
(
"%lf
\n
"
,
a
[
30
][
i
]);
}
printf
(
"%lf
\n
"
,
maxx
*
2086458231
/
minn
);
}
a
[
i
+
1
][
j
+
1
]
=
(
0.5
*
a
[
i
][
j
]);
```
data/1.算法初阶/6.蓝桥杯-模拟/4.分巧克力/solution.md
浏览文件 @
25e421c2
...
...
@@ -39,52 +39,57 @@
### before
```
cpp
#include <stdio.h>
#include <string.h>
int
co
[
100100
][
2
];
int
coun
(
int
n
,
int
x
)
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
sum
+=
(
co
[
i
][
0
]
/
x
)
*
(
co
[
i
][
1
]
/
x
);
}
return
sum
;
}
#include <bits/stdc++.h>
using
namespace
std
;
```
### after
```
cpp
int
main
()
{
int
n
;
int
k
;
scanf
(
"%d%d"
,
&
n
,
&
k
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
scanf
(
"%d%d"
,
&
co
[
i
][
0
],
&
co
[
i
][
1
]);
printf
(
"%d
\n
"
,
binary
(
n
,
k
));
}
```
## 答案
```
cpp
int
binary
(
int
n
,
int
k
)
bool
cmp
(
pair
<
int
,
int
>
a
,
pair
<
int
,
int
>
b
)
{
int
l
=
0
,
r
=
100000
;
while
(
l
<
r
)
return
a
.
first
>
b
.
first
;
}
int
main
()
{
int
n
,
k
;
vector
<
pair
<
int
,
int
>>
vec
;
cin
>>
n
>>
k
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
mid
=
(
r
-
l
)
/
2
+
l
;
if
(
coun
(
n
,
mid
)
<
k
)
r
=
mid
-
1
;
else
if
(
coun
(
n
,
mid
)
>
k
)
l
=
mid
+
1
;
else
return
mid
;
int
h
,
w
;
cin
>>
h
>>
w
;
if
(
h
>
w
)
{
int
temp
=
h
;
h
=
w
;
w
=
temp
;
}
vec
.
push_back
(
pair
<
int
,
int
>
(
h
,
w
));
}
return
r
;
sort
(
vec
.
begin
(),
vec
.
end
(),
cmp
);
int
s
=
vec
[
0
].
first
;
while
(
s
)
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
h
=
vec
[
i
].
first
;
int
w
=
vec
[
i
].
second
;
if
(
s
>
h
||
s
>
w
)
break
;
sum
+=
(
h
/
s
)
*
(
w
/
s
);
}
if
(
sum
>=
k
)
s
--
;
}
cout
<<
s
;
return
0
;
}
```
## 选项
...
...
@@ -93,59 +98,127 @@ int binary(int n, int k)
### A
```
cpp
int
binary
(
int
n
,
int
k
)
int
main
(
)
{
int
l
=
0
,
r
=
100000
;
while
(
l
<
r
)
int
n
,
k
;
int
h
[
100000
];
int
w
[
100000
];
cin
>>
n
>>
k
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
mid
=
(
r
-
l
)
/
2
+
l
;
if
(
coun
(
n
,
mid
)
<
k
)
r
=
mid
;
else
if
(
coun
(
n
,
mid
)
>
k
)
l
=
mid
;
else
return
mid
;
cin
>>
h
[
i
]
>>
w
[
i
];
}
return
r
;
int
len
=
100000
;
for
(;
len
>=
1
;
len
--
)
{
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
cnt
+=
(
h
[
i
]
/
len
)
*
(
w
[
i
]
/
len
);
}
if
(
cnt
>=
k
)
{
cout
<<
len
<<
endl
;
return
0
;
}
}
return
0
;
}
```
### B
```
cpp
int
binary
(
int
n
,
int
k
)
typedef
struct
{
int
l
=
0
,
r
=
100000
;
while
(
l
<
r
)
int
h
,
w
;
}
node
;
const
int
maxn
=
1e5
+
7
;
node
a
[
maxn
];
int
n
,
k
,
mx
=
-
1
;
bool
check
(
int
x
)
{
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
mid
=
(
r
-
l
)
/
2
+
l
;
if
(
coun
(
n
,
mid
)
>
k
)
r
=
mid
;
else
if
(
coun
(
n
,
mid
)
<
k
)
l
=
mid
;
cnt
+=
(
a
[
i
].
h
/
x
)
*
(
a
[
i
].
w
/
x
);
}
if
(
cnt
>=
k
)
return
true
;
else
return
false
;
}
int
main
()
{
scanf
(
"%d%d"
,
&
n
,
&
k
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
scanf
(
"%d%d"
,
&
a
[
i
].
h
,
&
a
[
i
].
w
);
if
(
a
[
i
].
w
>
mx
)
mx
=
a
[
i
].
w
;
if
(
a
[
i
].
h
>
mx
)
mx
=
a
[
i
].
h
;
}
int
l
=
1
,
r
=
mx
,
ans
;
while
(
l
<=
r
)
{
int
mid
=
(
l
+
r
)
/
2
;
if
(
check
(
mid
))
{
ans
=
mid
;
l
=
mid
+
1
;
}
else
return
mid
;
{
r
=
mid
-
1
;
}
}
return
r
;
printf
(
"%d
\n
"
,
ans
);
return
0
;
}
```
### C
```
cpp
int
co
[
100100
][
2
];
int
coun
(
int
n
,
int
x
)
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
sum
+=
(
co
[
i
][
0
]
/
x
)
*
(
co
[
i
][
1
]
/
x
);
}
return
sum
;
}
int
binary
(
int
n
,
int
k
)
{
int
l
=
0
,
r
=
100000
;
while
(
l
<
r
)
{
int
mid
=
(
r
-
l
)
/
2
+
l
;
if
(
coun
(
n
,
mid
)
>
k
)
if
(
coun
(
n
,
mid
)
<
k
)
r
=
mid
-
1
;
else
if
(
coun
(
n
,
mid
)
<
k
)
else
if
(
coun
(
n
,
mid
)
>
k
)
l
=
mid
+
1
;
else
return
mid
;
}
return
r
;
}
int
main
()
{
int
n
;
int
k
;
scanf
(
"%d%d"
,
&
n
,
&
k
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
scanf
(
"%d%d"
,
&
co
[
i
][
0
],
&
co
[
i
][
1
]);
printf
(
"%d
\n
"
,
binary
(
n
,
k
));
}
```
data/1.算法初阶/6.蓝桥杯-模拟/5.颠倒的价牌/solution.md
浏览文件 @
25e421c2
...
...
@@ -11,13 +11,14 @@
请根据这些信息计算:赔钱的那个价牌正确的价格应该是多少?
下面的哪一项是错误的?
## aop
### before
```
cpp
#include <
iostream
>
#include <
bits/stdc++.h
>
using
namespace
std
;
```
### after
...
...
@@ -31,15 +32,15 @@ using namespace std;
```
cpp
int
main
()
{
int
num1
[
7
]
=
{
0
,
1
,
2
,
5
,
6
,
8
,
9
};
int
num2
[
7
]
=
{
0
,
1
,
2
,
5
,
9
,
8
,
6
};
int
profit1
[
1111
][
2
];
int
profit2
[
1111
][
2
];
int
before_reverse
;
int
after_reverse
;
int
num1
[
7
]
=
{
0
,
1
,
2
,
5
,
6
,
8
,
9
};
int
num2
[
7
]
=
{
0
,
1
,
2
,
5
,
9
,
8
,
6
};
int
profit1
[
1111
][
2
];
int
profit2
[
1111
][
2
];
int
before_reverse
;
int
after_reverse
;
int
i
=
0
;
int
j
=
0
;
for
(
int
a
=
1
;
a
<
7
;
a
++
)
for
(
int
a
=
1
;
a
<
7
;
a
++
)
{
for
(
int
b
=
0
;
b
<
7
;
b
++
)
{
...
...
@@ -49,19 +50,19 @@ int main()
{
before_reverse
=
num1
[
a
]
*
1000
+
num1
[
b
]
*
100
+
num1
[
c
]
*
10
+
num1
[
d
];
after_reverse
=
num2
[
d
]
*
1000
+
num2
[
c
]
*
100
+
num2
[
b
]
*
10
+
num2
[
a
];
if
(
after_reverse
-
before_reverse
>
-
300
&&
after_reverse
-
before_reverse
<
-
200
)
{
profit1
[
i
][
0
]
=
before_reverse
;
profit1
[
i
][
1
]
=
after_reverse
-
before_reverse
;
i
++
;
}
else
if
(
after_reverse
-
before_reverse
>
800
&&
after_reverse
-
before_reverse
<
900
)
{
profit1
[
j
][
0
]
=
before_reverse
;
profit2
[
j
][
1
]
=
after_reverse
-
before_reverse
;
profit1
[
j
][
0
]
=
after_reverse
-
before_reverse
;
profit2
[
j
][
1
]
=
before_reverse
;
j
++
;
}
}
...
...
@@ -89,57 +90,81 @@ int main()
### A
```
cpp
int
main
(
)
void
i2s
(
int
num
,
string
&
str
)
{
int
num1
[
7
]
=
{
0
,
1
,
2
,
5
,
6
,
8
,
9
};
int
num2
[
7
]
=
{
0
,
1
,
2
,
5
,
9
,
8
,
6
};
int
profit1
[
1111
][
2
];
int
profit2
[
1111
][
2
];
int
before_reverse
;
int
after_reverse
;
int
i
=
0
;
int
j
=
0
;
for
(
int
a
=
1
;
a
<
7
;
a
++
)
stringstream
ss
;
ss
<<
num
;
ss
>>
str
;
}
void
s2i
(
string
&
str
,
int
&
num
)
{
stringstream
ss
;
ss
<<
str
;
ss
>>
num
;
}
char
to
(
char
x
)
{
if
(
x
==
'6'
)
return
'9'
;
else
if
(
x
==
'9'
)
return
'6'
;
else
return
x
;
}
string
reserve
(
const
string
&
str
)
{
string
ans
;
for
(
int
i
=
3
;
i
>=
0
;
i
--
)
{
for
(
int
b
=
0
;
b
<
7
;
b
++
)
{
for
(
int
c
=
0
;
c
<
7
;
c
++
)
{
for
(
int
d
=
0
;
d
<
7
;
d
++
)
{
before_reverse
=
num1
[
a
]
*
1000
+
num1
[
b
]
*
100
+
num1
[
c
]
*
10
+
num1
[
d
];
after_reverse
=
num2
[
d
]
*
1000
+
num2
[
c
]
*
100
+
num2
[
b
]
*
10
+
num2
[
a
];
if
(
after_reverse
-
before_reverse
>
-
300
&&
after_reverse
-
before_reverse
<
-
200
)
{
profit1
[
i
][
0
]
=
before_reverse
;
profit1
[
i
][
1
]
=
after_reverse
-
before_reverse
;
i
++
;
}
else
if
(
after_reverse
-
before_reverse
>
800
&&
after_reverse
-
before_reverse
<
900
)
{
profit1
[
j
][
0
]
=
before_reverse
;
profit2
[
j
][
1
]
=
after_reverse
-
before_reverse
;
j
++
;
}
}
}
}
ans
.
insert
(
ans
.
end
(),
to
(
str
[
i
]));
}
return
ans
;
}
struct
price
{
int
a
,
b
,
c
;
};
vector
<
price
>
v1
;
vector
<
price
>
v2
;
int
main
()
{
int
answer
=
0
;
for
(
int
a
=
0
;
a
<
i
;
a
++
)
for
(
int
i
=
1000
;
i
<
10000
;
i
++
)
{
for
(
int
b
=
0
;
b
<
j
;
b
++
)
string
str
;
i2s
(
i
,
str
);
if
(
str
.
find
(
'3'
)
!=
string
::
npos
||
str
.
find
(
'4'
)
!=
string
::
npos
||
str
.
find
(
'7'
)
!=
string
::
npos
||
str
.
rfind
(
'0'
)
==
3
)
continue
;
string
r
=
reserve
(
str
);
int
r_int
;
s2i
(
r
,
r_int
);
int
plus
=
r_int
-
i
;
if
(
plus
>
-
300
&&
plus
<
-
200
)
{
if
(
profit1
[
a
][
1
]
+
profit2
[
b
][
1
]
==
558
)
price
p
=
{
i
,
r_int
,
plus
};
v1
.
push_back
(
p
);
}
else
if
(
plus
>
800
&&
plus
<
900
)
{
price
p
=
{
i
,
r_int
,
plus
};
v2
.
push_back
(
p
);
}
for
(
int
i
=
0
;
i
<
v1
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
v2
.
size
();
j
++
)
{
answer
=
profit1
[
b
][
1
];
if
(
v1
[
i
].
c
+
v2
[
j
].
c
==
558
)
{
answer
=
v1
[
i
].
a
;
}
}
}
}
cout
<<
answer
<<
endl
;
cout
<<
answer
;
return
0
;
}
```
...
...
@@ -147,57 +172,56 @@ int main()
### B
```
cpp
#define ll long long
using
namespace
std
;
int
flag
(
int
n
)
{
if
(
n
%
10
==
0
)
return
0
;
while
(
n
>
0
)
{
int
t
=
n
%
10
;
if
(
t
==
3
||
t
==
4
||
t
==
7
)
return
0
;
n
/=
10
;
}
return
1
;
}
int
reverse
(
int
n
)
{
int
ans
=
0
;
while
(
n
>
0
)
{
int
t
=
n
%
10
;
if
(
t
==
6
)
t
=
9
;
else
if
(
t
==
9
)
t
=
6
;
ans
=
ans
*
10
+
t
;
n
/=
10
;
}
return
ans
;
}
int
main
()
{
int
num1
[
7
]
=
{
0
,
1
,
2
,
5
,
6
,
8
,
9
};
int
num2
[
7
]
=
{
0
,
1
,
2
,
5
,
9
,
8
,
6
};
int
profit1
[
1111
][
2
];
int
profit2
[
1111
][
2
];
int
before_reverse
;
int
after_reverse
;
int
i
=
0
;
int
j
=
0
;
for
(
int
a
=
1
;
a
<
7
;
a
++
)
int
ans1
,
ans2
;
for
(
int
i
=
1000
;
i
<=
10000
;
i
++
)
{
for
(
int
b
=
0
;
b
<
7
;
b
++
)
for
(
int
j
=
1000
;
j
<=
10000
;
j
++
)
{
for
(
int
c
=
0
;
c
<
7
;
c
++
)
if
(
flag
(
i
)
&&
flag
(
j
)
)
{
for
(
int
d
=
0
;
d
<
7
;
d
++
)
int
t1
=
i
-
reverse
(
i
);
int
t2
=
j
-
reverse
(
j
);
if
(
t1
>
200
&&
t1
<
300
&&
t2
<
-
800
&&
t2
>
-
900
&&
t2
+
t1
==
-
558
)
{
before_reverse
=
num1
[
a
]
*
1000
+
num1
[
b
]
*
100
+
num1
[
c
]
*
10
+
num1
[
d
];
after_reverse
=
num2
[
d
]
*
1000
+
num2
[
c
]
*
100
+
num2
[
b
]
*
10
+
num2
[
a
];
if
(
after_reverse
-
before_reverse
>
-
300
&&
after_reverse
-
before_reverse
<
-
200
)
{
profit1
[
i
][
0
]
=
before_reverse
;
profit1
[
i
][
1
]
=
after_reverse
-
before_reverse
;
i
++
;
}
else
if
(
after_reverse
-
before_reverse
>
800
&&
after_reverse
-
before_reverse
<
900
)
{
profit1
[
j
][
0
]
=
before_reverse
;
profit2
[
j
][
1
]
=
after_reverse
-
before_reverse
;
j
++
;
}
ans1
=
i
,
ans2
=
j
;
cout
<<
ans1
<<
endl
;
break
;
}
}
}
}
int
answer
=
0
;
for
(
int
a
=
0
;
a
<
i
;
a
++
)
{
for
(
int
b
=
0
;
b
<
j
;
b
++
)
{
if
(
profit1
[
a
][
1
]
+
profit2
[
b
][
1
]
==
558
)
{
answer
=
profit1
[
b
][
0
];
}
}
}
cout
<<
answer
<<
endl
;
return
0
;
}
```
...
...
@@ -205,57 +229,44 @@ int main()
### C
```
cpp
int
num
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
int
dnum
[]
=
{
0
,
1
,
2
,
-
1
,
-
1
,
5
,
9
,
-
1
,
8
,
6
};
int
main
()
{
int
num1
[
7
]
=
{
0
,
1
,
2
,
5
,
6
,
8
,
9
};
int
num2
[
7
]
=
{
0
,
1
,
2
,
5
,
9
,
8
,
6
};
int
profit1
[
1111
][
2
];
int
profit2
[
1111
][
2
];
int
before_reverse
;
int
after_reverse
;
int
i
=
0
;
int
j
=
0
;
for
(
int
a
=
1
;
a
<
7
;
a
++
)
{
for
(
int
b
=
0
;
b
<
7
;
b
++
)
{
for
(
int
c
=
0
;
c
<
7
;
c
++
)
{
for
(
int
d
=
0
;
d
<
7
;
d
++
)
int
a
[
10
],
b
[
10
];
int
answer
=
0
;
for
(
a
[
1
]
=
1
;
a
[
1
]
<=
9
;
++
a
[
1
])
for
(
a
[
2
]
=
0
;
a
[
2
]
<=
9
;
++
a
[
2
])
for
(
a
[
3
]
=
0
;
a
[
3
]
<=
9
;
++
a
[
3
])
for
(
a
[
4
]
=
1
;
a
[
4
]
<=
9
;
++
a
[
4
])
{
before_reverse
=
num1
[
a
]
*
1000
+
num1
[
b
]
*
100
+
num1
[
c
]
*
10
+
num1
[
d
];
after_reverse
=
num2
[
d
]
*
1000
+
num2
[
c
]
*
100
+
num2
[
b
]
*
10
+
num2
[
a
];
if
(
after_reverse
-
before_reverse
>
-
300
&&
after_reverse
-
before_reverse
<
-
200
)
if
(
dnum
[
a
[
1
]]
>=
0
&&
dnum
[
a
[
2
]]
>=
0
&&
dnum
[
a
[
3
]]
>=
0
&&
dnum
[
a
[
3
]]
>=
0
)
{
profit1
[
i
][
0
]
=
before_reverse
;
profit1
[
i
][
1
]
=
after_reverse
-
before_reverse
;
i
++
;
}
else
if
(
after_reverse
-
before_reverse
>
800
&&
after_reverse
-
before_reverse
<
900
)
{
profit1
[
j
][
0
]
=
before_reverse
;
profit2
[
j
][
1
]
=
after_reverse
-
before_reverse
;
j
++
;
int
x
=
a
[
1
]
*
1000
+
a
[
2
]
*
100
+
a
[
3
]
*
10
+
a
[
4
];
int
y
=
dnum
[
a
[
4
]]
*
1000
+
dnum
[
a
[
3
]]
*
100
+
dnum
[
a
[
2
]]
*
10
+
dnum
[
a
[
1
]];
if
(
x
-
y
>=
200
&&
x
-
y
<=
300
)
{
for
(
b
[
1
]
=
1
;
b
[
1
]
<=
9
;
++
b
[
1
])
for
(
b
[
2
]
=
0
;
b
[
2
]
<=
9
;
++
b
[
2
])
for
(
b
[
3
]
=
0
;
b
[
3
]
<=
9
;
++
b
[
3
])
for
(
b
[
4
]
=
1
;
b
[
4
]
<=
9
;
++
b
[
4
])
{
if
(
dnum
[
b
[
1
]]
>=
0
&&
dnum
[
b
[
2
]]
>=
0
&&
dnum
[
b
[
3
]]
>=
0
&&
dnum
[
b
[
3
]]
>=
0
)
{
int
i
=
b
[
1
]
*
1000
+
b
[
2
]
*
100
+
b
[
3
]
*
10
+
b
[
4
];
int
j
=
dnum
[
b
[
4
]]
*
1000
+
dnum
[
b
[
3
]]
*
100
+
dnum
[
b
[
2
]]
*
10
+
dnum
[
b
[
1
]];
if
(
j
-
i
>=
800
&&
j
-
i
<=
900
)
{
if
(
j
-
i
+
y
-
x
==
558
)
answer
=
x
;
}
}
}
}
}
}
}
}
}
int
answer
=
0
;
for
(
int
a
=
0
;
a
<
i
;
a
++
)
{
for
(
int
b
=
0
;
b
<
j
;
b
++
)
{
if
(
profit1
[
a
][
1
]
+
profit2
[
b
][
1
]
==
558
)
{
answer
=
profit1
[
0
][
b
];
}
}
}
cout
<<
answer
<<
endl
;
cout
<<
answer
;
return
0
;
}
```
data/1.算法初阶/6.蓝桥杯-模拟/6.方程整数解/solution.md
浏览文件 @
25e421c2
...
...
@@ -19,35 +19,21 @@
**样例输入**
```
4
1000
```
**样例输出**
```
No Solution
6 8 30
10 18 24
```
## aop
### before
以下程序可以实现该功能,请你计算该程序的算法复杂度:
```
cpp
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
using
namespace
std
;
```
### after
```
cpp
```
## 答案
```
cpp
int
main
()
{
int
n
;
...
...
@@ -77,7 +63,25 @@ int main()
return
0
;
}
```
## aop
### before
```
cpp
```
### after
```
cpp
```
## 答案
```
cpp
O
(
n
^
1.5
)
```
## 选项
...
...
@@ -85,101 +89,17 @@ int main()
### A
```
cpp
int
main
()
{
int
n
;
bool
flag
=
false
;
while
(
cin
>>
n
)
{
flag
=
false
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
for
(
int
j
=
i
;
j
<=
n
;
j
++
)
{
for
(
int
k
=
j
;
k
<=
n
;
k
++
)
{
if
(
i
*
i
+
j
*
j
+
k
*
k
==
n
)
{
cout
<<
i
<<
' '
<<
j
<<
' '
<<
k
<<
endl
;
flag
=
true
;
}
else
if
(
i
*
i
+
j
*
j
+
k
*
k
>
n
)
break
;
}
}
}
if
(
!
flag
)
cout
<<
"No Solution"
<<
endl
;
}
return
0
;
}
O
(
n
^
3
)
```
### B
```
cpp
int
main
()
{
int
n
;
bool
flag
=
false
;
while
(
cin
>>
n
)
{
flag
=
false
;
for
(
int
i
=
1
;
i
<
sqrt
(
n
);
i
++
)
{
for
(
int
j
=
1
;
j
<
sqrt
(
n
);
j
++
)
{
for
(
int
k
=
1
;
k
<
sqrt
(
n
);
k
++
)
{
if
(
i
*
i
+
j
*
j
+
k
*
k
==
n
)
{
cout
<<
i
<<
' '
<<
j
<<
' '
<<
k
<<
endl
;
flag
=
true
;
}
else
if
(
i
*
i
+
j
*
j
+
k
*
k
>
n
)
break
;
}
}
}
if
(
!
flag
)
cout
<<
"No Solution"
<<
endl
;
}
return
0
;
}
O
(
n
^
2
)
```
### C
```
cpp
int
main
()
{
int
n
;
bool
flag
=
false
;
while
(
cin
>>
n
)
{
flag
=
false
;
for
(
int
i
=
1
;
i
<=
sqrt
(
n
);
i
++
)
{
for
(
int
j
=
1
;
j
<=
sqrt
(
n
);
j
++
)
{
for
(
int
k
=
j
;
k
<=
sqrt
(
n
);
k
++
)
{
if
(
i
*
i
+
j
*
j
+
k
*
k
==
n
)
{
cout
<<
i
<<
' '
<<
j
<<
' '
<<
k
<<
endl
;
flag
=
true
;
}
else
if
(
i
*
i
+
j
*
j
+
k
*
k
>
n
)
break
;
}
}
}
if
(
!
flag
)
cout
<<
"No Solution"
<<
endl
;
}
return
0
;
}
O
(
n
^
2.5
)
```
data/1.算法初阶/6.蓝桥杯-模拟/7.7段码/solution.md
浏览文件 @
25e421c2
...
...
@@ -25,89 +25,18 @@
### before
```
cpp
#include <iostream>
using
namespace
std
;
int
use
[
10
];
int
ans
,
e
[
10
][
10
],
father
[
10
];
void
init
()
{
e
[
1
][
2
]
=
e
[
1
][
6
]
=
1
;
e
[
2
][
1
]
=
e
[
2
][
7
]
=
e
[
2
][
3
]
=
1
;
e
[
3
][
2
]
=
e
[
3
][
4
]
=
e
[
3
][
7
]
=
1
;
e
[
4
][
3
]
=
e
[
4
][
5
]
=
1
;
e
[
5
][
4
]
=
e
[
5
][
6
]
=
e
[
5
][
7
]
=
1
;
e
[
6
][
1
]
=
e
[
6
][
5
]
=
e
[
6
][
7
]
=
1
;
}
int
find
(
int
a
)
{
if
(
father
[
a
]
==
a
)
return
a
;
father
[
a
]
=
find
(
father
[
a
]);
return
father
[
a
];
}
```
### after
```
cpp
int
main
()
{
init
();
dfs
(
1
);
cout
<<
ans
;
return
0
;
}
```
## 答案
```
cpp
void
dfs
(
int
d
)
{
if
(
d
>
7
)
{
for
(
int
i
=
1
;
i
<=
7
;
i
++
)
{
father
[
i
]
=
i
;
}
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
for
(
int
j
=
1
;
j
<
8
;
j
++
)
{
if
(
e
[
i
][
j
]
==
1
&&
use
[
i
]
&&
use
[
j
])
{
int
fx
=
find
(
i
);
int
fy
=
find
(
j
);
if
(
fx
!=
fy
)
{
father
[
fx
]
=
fy
;
}
}
}
}
int
k
=
0
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
use
[
i
]
&&
father
[
i
]
==
i
)
{
k
++
;
}
}
if
(
k
==
1
)
{
ans
++
;
}
return
;
}
use
[
d
]
=
1
;
dfs
(
d
+
1
);
use
[
d
]
=
0
;
dfs
(
d
+
1
);
}
80
```
## 选项
...
...
@@ -115,131 +44,17 @@ void dfs(int d)
### A
```
cpp
void
dfs
(
int
d
)
{
if
(
d
>
7
)
{
for
(
int
i
=
1
;
i
<=
7
;
i
++
)
{
father
[
i
]
=
i
;
}
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
for
(
int
j
=
1
;
j
<
8
;
j
++
)
{
if
(
e
[
i
][
j
]
==
1
&&
use
[
i
]
&&
use
[
j
])
{
int
fx
=
find
(
i
);
int
fy
=
find
(
j
);
if
(
fx
!=
fy
)
{
father
[
fx
]
=
fy
;
}
}
}
}
int
k
=
0
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
father
[
i
]
==
i
)
{
k
++
;
}
}
if
(
k
==
1
)
{
ans
++
;
}
return
;
}
use
[
d
]
=
1
;
dfs
(
d
+
1
);
use
[
d
]
=
0
;
dfs
(
d
+
1
);
}
90
```
### B
```
cpp
void
dfs
(
int
d
)
{
if
(
d
>
7
)
{
for
(
int
i
=
1
;
i
<=
7
;
i
++
)
{
father
[
i
]
=
i
;
}
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
for
(
int
j
=
1
;
j
<
8
;
j
++
)
{
if
(
e
[
i
][
j
]
==
1
)
{
int
fx
=
find
(
i
);
int
fy
=
find
(
j
);
if
(
fx
!=
fy
)
{
father
[
fx
]
=
fy
;
}
}
}
}
int
k
=
0
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
use
[
i
]
&&
father
[
i
]
==
i
)
{
k
++
;
}
}
if
(
k
==
1
)
{
ans
++
;
}
return
;
}
use
[
d
]
=
1
;
dfs
(
d
+
1
);
use
[
d
]
=
0
;
dfs
(
d
+
1
);
}
70
```
### C
```
cpp
void
dfs
(
int
d
)
{
if
(
d
>
7
)
{
for
(
int
i
=
1
;
i
<=
7
;
i
++
)
{
father
[
i
]
=
i
;
}
int
k
=
0
;
for
(
int
i
=
1
;
i
<
8
;
i
++
)
{
if
(
use
[
i
]
&&
father
[
i
]
==
i
)
{
k
++
;
}
}
if
(
k
==
1
)
{
ans
++
;
}
return
;
}
use
[
d
]
=
1
;
dfs
(
d
+
1
);
use
[
d
]
=
0
;
dfs
(
d
+
1
);
}
78
```
data/1.算法初阶/6.蓝桥杯-模拟/8.分糖果/solution.md
浏览文件 @
25e421c2
...
...
@@ -29,12 +29,14 @@
4
```
以下错误的一项是?
## aop
### before
```
cpp
#include <
iostream
>
#include <
bits/stdc++.h
>
using
namespace
std
;
```
### after
...
...
@@ -50,42 +52,35 @@ int main()
{
int
n
;
cin
>>
n
;
int
*
Candy
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
cin
>>
Candy
[
i
];
}
int
total
=
0
;
while
(
1
)
int
a
[
n
],
tmp
[
n
];
for
(
int
i
=
0
;
i
<
n
;
++
i
)
cin
>>
a
[
i
];
int
cnt
=
0
,
t
;
bool
f
=
true
;
while
(
true
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
f
=
true
;
for
(
int
i
=
1
;
i
<
n
;
++
i
)
if
(
a
[
0
]
!=
a
[
i
])
{
f
lag
=
false
;
f
=
false
;
break
;
}
}
if
(
flag
==
true
)
if
(
f
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
-
1
;
i
>=
0
;
i
--
)
for
(
int
i
=
0
;
i
<
n
;
++
i
)
a
[
i
]
=
tmp
[
i
]
=
a
[
i
]
>>
1
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
if
(
i
==
0
)
{
Candy
[
0
]
=
Candy
[
0
]
/
2
+
temp
/
2
;
}
else
Candy
[
i
]
=
Candy
[
i
]
/
2
+
Candy
[
i
-
1
]
/
2
;
if
(
Candy
[
i
]
%
2
!=
0
)
{
Candy
[
i
]
+=
1
;
total
+=
1
;
}
t
=
(
i
-
1
+
n
)
%
n
;
a
[
t
]
+=
tmp
[
i
];
if
(
a
[
t
]
&&
1
)
++
a
[
t
],
++
cnt
;
}
}
cout
<<
total
<<
endl
;
cout
<<
cnt
;
return
0
;
}
```
## 选项
...
...
@@ -96,90 +91,104 @@ int main()
```
cpp
int
main
()
{
int
n
;
int
n
,
m
,
count
=
0
,
t
=
0
;
cin
>>
n
;
int
*
Candy
=
new
int
[
n
]
;
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
cin
>>
Candy
[
i
];
cin
>>
m
;
v
.
push_back
(
m
);
}
int
total
=
0
;
while
(
1
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
{
if
(
v
[
0
]
!=
v
[
i
])
flag
=
false
;
break
;
}
}
if
(
flag
==
true
)
if
(
flag
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
;
i
>=
0
;
i
--
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
if
(
i
==
0
)
{
Candy
[
0
]
=
Candy
[
0
]
/
2
+
temp
/
2
;
}
else
Candy
[
i
]
=
Candy
[
i
]
/
2
+
Candy
[
i
-
1
]
/
2
;
if
(
Candy
[
i
]
%
2
!=
0
)
v
[
i
]
=
v
[
i
]
/
2
;
}
int
temp
=
v
[
n
-
1
];
for
(
int
i
=
n
-
1
;
i
>
0
;
i
--
)
{
v
[
i
]
+=
v
[
i
-
1
];
}
v
[
0
]
+=
temp
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
if
(
v
[
i
]
&
1
)
{
Candy
[
i
]
+=
1
;
total
+=
1
;
v
[
i
]
++
;
count
++
;
}
}
}
cout
<<
total
<<
endl
;
cout
<<
count
<<
endl
;
return
0
;
}
```
### B
```
cpp
int
n
;
int
a
[
100
];
int
main
()
{
int
n
;
bool
flag
;
cin
>>
n
;
int
*
Candy
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
cin
>>
Candy
[
i
];
cin
>>
a
[
i
];
}
int
total
=
0
;
while
(
1
)
int
nAns
=
0
;
int
temp
;
while
(
true
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
]
)
if
(
1
==
i
)
{
flag
=
false
;
break
;
temp
=
a
[
i
]
/
2
;
a
[
i
]
-=
temp
;
}
else
{
a
[
i
-
1
]
+=
a
[
i
]
/
2
;
a
[
i
]
-=
a
[
i
]
/
2
;
}
}
if
(
flag
==
true
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
;
i
>=
0
;
i
--
)
a
[
n
]
+=
temp
;
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
{
if
(
i
==
0
)
if
(
a
[
i
]
%
2
==
1
)
{
Candy
[
0
]
=
Candy
[
0
]
/
2
+
temp
/
2
;
a
[
i
]
+=
1
;
nAns
++
;
}
else
Candy
[
i
]
=
Candy
[
i
]
/
2
+
Candy
[
i
-
1
]
/
2
;
if
(
Candy
[
i
]
%
2
==
0
)
}
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
if
(
a
[
i
]
!=
a
[
i
+
1
])
{
Candy
[
i
]
+=
1
;
total
+=
1
;
flag
=
false
;
}
}
if
(
flag
==
true
)
{
break
;
}
}
cout
<<
total
<<
endl
;
cout
<<
nAns
<<
endl
;
return
0
;
}
```
...
...
@@ -218,7 +227,7 @@ int main()
}
else
Candy
[
i
]
=
Candy
[
i
]
/
2
+
Candy
[
i
-
1
]
/
2
;
if
(
Candy
[
i
]
%
2
=
=
0
)
if
(
Candy
[
i
]
%
2
!
=
0
)
{
Candy
[
i
]
+=
1
;
total
+=
1
;
...
...
@@ -227,5 +236,4 @@ int main()
}
cout
<<
total
<<
endl
;
}
```
data/1.算法初阶/6.蓝桥杯-模拟/9.夺冠概率/solution.md
浏览文件 @
25e421c2
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录