Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_algorithm
提交
3029e901
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看板
提交
3029e901
编写于
10月 29, 2021
作者:
每日一练社区
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update exercises
上级
41c78088
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
336 addition
and
40 deletion
+336
-40
.gitignore
.gitignore
+2
-1
data/1.算法初阶/1.蓝桥杯/分巧克力/solution.cpp
data/1.算法初阶/1.蓝桥杯/分巧克力/solution.cpp
+2
-5
data/1.算法初阶/1.蓝桥杯/分巧克力/solution.md
data/1.算法初阶/1.蓝桥杯/分巧克力/solution.md
+82
-5
data/1.算法初阶/1.蓝桥杯/分数/solution.cpp
data/1.算法初阶/1.蓝桥杯/分数/solution.cpp
+6
-6
data/1.算法初阶/1.蓝桥杯/分数/solution.md
data/1.算法初阶/1.蓝桥杯/分数/solution.md
+65
-6
data/1.算法初阶/1.蓝桥杯/分糖果/solution.cpp
data/1.算法初阶/1.蓝桥杯/分糖果/solution.cpp
+13
-13
data/1.算法初阶/1.蓝桥杯/分糖果/solution.md
data/1.算法初阶/1.蓝桥杯/分糖果/solution.md
+166
-4
src/__pycache__/tree.cpython-38.pyc
src/__pycache__/tree.cpython-38.pyc
+0
-0
未找到文件。
.gitignore
浏览文件 @
3029e901
...
@@ -11,4 +11,5 @@ leetcode_template.md
...
@@ -11,4 +11,5 @@ leetcode_template.md
auto_gen_leetcode_tem.py
auto_gen_leetcode_tem.py
leetcode_helper.py
leetcode_helper.py
lanqiao_helper.py
lanqiao_helper.py
lanqiao_template.md
lanqiao_template.md
\ No newline at end of file
./src/__pycache__/*.pyc
\ No newline at end of file
data/1.算法初阶/1.蓝桥杯/分巧克力/solution.cpp
浏览文件 @
3029e901
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
#include <string.h>
#include <string.h>
int
co
[
100100
][
2
];
int
co
[
100100
][
2
];
//n块巧克力,分成x*x型的。
//返回巧克力的块数
int
coun
(
int
n
,
int
x
)
int
coun
(
int
n
,
int
x
)
{
{
int
sum
=
0
;
int
sum
=
0
;
...
@@ -14,16 +12,15 @@ int coun(int n, int x)
...
@@ -14,16 +12,15 @@ int coun(int n, int x)
return
sum
;
return
sum
;
}
}
//二分求解
int
binary
(
int
n
,
int
k
)
int
binary
(
int
n
,
int
k
)
{
{
int
l
=
0
,
r
=
100000
;
int
l
=
0
,
r
=
100000
;
while
(
l
<
r
)
while
(
l
<
r
)
{
{
int
mid
=
(
r
-
l
)
/
2
+
l
;
int
mid
=
(
r
-
l
)
/
2
+
l
;
if
(
coun
(
n
,
mid
)
<
k
)
if
(
coun
(
n
,
mid
)
>
k
)
r
=
mid
-
1
;
r
=
mid
-
1
;
else
if
(
coun
(
n
,
mid
)
>
k
)
else
if
(
coun
(
n
,
mid
)
<
k
)
l
=
mid
+
1
;
l
=
mid
+
1
;
else
else
return
mid
;
return
mid
;
...
...
data/1.算法初阶/1.蓝桥杯/分巧克力/solution.md
浏览文件 @
3029e901
...
@@ -29,30 +29,107 @@
...
@@ -29,30 +29,107 @@
## aop
## aop
### before
### before
```
cpp
```
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
;
}
```
```
### after
### after
```
cpp
```
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
```
cpp
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
)
r
=
mid
-
1
;
else
if
(
coun
(
n
,
mid
)
>
k
)
l
=
mid
+
1
;
else
return
mid
;
}
return
r
;
}
```
```
## 选项
## 选项
### A
### A
```
cpp
```
cpp
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
)
r
=
mid
;
else
if
(
coun
(
n
,
mid
)
>
k
)
l
=
mid
;
else
return
mid
;
}
return
r
;
}
```
```
### B
### B
```
cpp
```
cpp
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
)
r
=
mid
;
else
if
(
coun
(
n
,
mid
)
<
k
)
l
=
mid
;
else
return
mid
;
}
return
r
;
}
```
```
### C
### C
```
cpp
```
cpp
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
)
r
=
mid
-
1
;
else
if
(
coun
(
n
,
mid
)
<
k
)
l
=
mid
+
1
;
else
return
mid
;
}
return
r
;
}
```
```
data/1.算法初阶/1.蓝桥杯/分数/solution.cpp
浏览文件 @
3029e901
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using
namespace
std
;
using
namespace
std
;
long
pow_2
(
int
b
)
//快速幂运算
long
pow_2
(
int
b
)
{
{
long
x
=
2
;
long
x
=
2
;
long
res
=
1
;
long
res
=
1
;
while
(
b
>
0
)
while
(
b
>
0
)
{
{
if
(
b
&
1
)
if
(
b
&
1
)
res
*
=
x
;
res
=
x
;
b
>>=
1
;
//右移一位
b
>>=
1
;
x
=
x
*
x
;
x
=
x
*
x
;
}
}
return
res
;
return
res
;
}
}
int
gcd
(
long
a
,
long
b
)
//求出最大公约数
int
gcd
(
long
a
,
long
b
)
{
{
if
(
b
==
0
)
if
(
b
==
0
)
return
a
;
return
a
;
...
@@ -21,6 +21,6 @@ int gcd(long a, long b) //求出最大公约数
...
@@ -21,6 +21,6 @@ int gcd(long a, long b) //求出最大公约数
}
}
int
main
()
int
main
()
{
{
cout
<<
gcd
(
pow_2
(
20
)
-
1
,
pow_2
(
19
))
<<
endl
;
//最大公约数
cout
<<
gcd
(
pow_2
(
20
)
-
1
,
pow_2
(
19
))
<<
endl
;
cout
<<
pow_2
(
20
)
-
1
<<
"/"
<<
pow_2
(
19
)
<<
endl
;
//输出分子分母
cout
<<
pow_2
(
20
)
-
1
<<
"/"
<<
pow_2
(
19
)
<<
endl
;
}
}
data/1.算法初阶/1.蓝桥杯/分数/solution.md
浏览文件 @
3029e901
...
@@ -6,30 +6,89 @@
...
@@ -6,30 +6,89 @@
## aop
## aop
### before
### before
```
cpp
```
cpp
#include <bits/stdc++.h>
using
namespace
std
;
```
```
### after
### after
```
cpp
```
cpp
int
gcd
(
long
a
,
long
b
)
{
if
(
b
==
0
)
return
a
;
return
gcd
(
b
,
a
%
b
);
}
int
main
()
{
cout
<<
gcd
(
pow_2
(
20
)
-
1
,
pow_2
(
19
))
<<
endl
;
cout
<<
pow_2
(
20
)
-
1
<<
"/"
<<
pow_2
(
19
)
<<
endl
;
}
```
```
## 答案
## 答案
```
cpp
```
cpp
long
pow_2
(
int
b
)
{
long
x
=
2
;
long
res
=
1
;
while
(
b
>
0
)
{
if
(
b
&
1
)
res
*=
x
;
b
>>=
1
;
x
=
x
*
x
;
}
return
res
;
}
```
```
## 选项
## 选项
### A
### A
```
cpp
```
cpp
long
pow_2
(
int
b
)
{
long
x
=
2
;
long
res
=
1
;
while
(
b
>
0
)
{
if
(
b
&
1
)
res
*=
x
;
b
<<=
1
;
x
=
x
*
x
;
}
return
res
;
}
```
```
### B
### B
```
cpp
```
cpp
long
pow_2
(
int
b
)
{
long
x
=
2
;
long
res
=
1
;
while
(
b
>
0
)
{
if
(
b
&&
1
)
res
*=
x
;
b
<<=
1
;
x
=
x
*
x
;
}
return
res
;
}
```
```
### C
### C
```
cpp
```
cpp
long
pow_2
(
int
b
)
{
long
x
=
2
;
long
res
=
1
;
while
(
b
>
0
)
{
if
(
b
&
1
)
res
=
x
;
b
>>=
1
;
x
=
x
*
x
;
}
return
res
;
}
```
```
data/1.算法初阶/1.蓝桥杯/分糖果/solution.cpp
浏览文件 @
3029e901
...
@@ -2,40 +2,40 @@
...
@@ -2,40 +2,40 @@
using
namespace
std
;
using
namespace
std
;
int
main
()
int
main
()
{
{
int
n
;
//小朋友数量
int
n
;
cin
>>
n
;
cin
>>
n
;
int
*
Candy
=
new
int
[
n
];
//存储每个小朋友的糖果数
int
*
Candy
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
{
cin
>>
Candy
[
i
];
cin
>>
Candy
[
i
];
}
}
int
total
=
0
;
//补发的糖果总数
int
total
=
0
;
while
(
1
)
while
(
1
)
{
{
bool
flag
=
true
;
//判断每人糖果数量是否相同
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
if
(
Candy
[
0
]
!=
Candy
[
i
])
{
//不相同
{
flag
=
false
;
flag
=
false
;
break
;
break
;
}
}
}
}
if
(
flag
==
true
)
//数量相同,退出循环
if
(
flag
==
true
)
break
;
break
;
int
temp
=
Candy
[
n
-
1
];
//记录最后一个小朋友手中的糖果
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
-
1
;
i
>=
0
;
i
--
)
for
(
int
i
=
n
-
1
;
i
>=
0
;
i
--
)
{
{
if
(
i
==
0
)
if
(
i
==
0
)
{
//如果是第一个小朋友
{
Candy
[
0
]
=
Candy
[
0
]
/
2
+
temp
/
2
;
//最后一个小朋友获得最初第一个人的一半
Candy
[
0
]
=
Candy
[
0
]
/
2
+
temp
/
2
;
}
}
else
else
Candy
[
i
]
=
Candy
[
i
]
/
2
+
Candy
[
i
-
1
]
/
2
;
// 每个小朋友都把自己的糖果分一半给左手边的孩子
Candy
[
i
]
=
Candy
[
i
]
/
2
+
Candy
[
i
-
1
]
/
2
;
if
(
Candy
[
i
]
%
2
!
=
0
)
if
(
Candy
[
i
]
%
2
=
=
0
)
{
//如果此时手中为奇数,则补糖果
{
Candy
[
i
]
+=
1
;
Candy
[
i
]
+=
1
;
total
+=
1
;
//补发数量加1
total
+=
1
;
}
}
}
}
}
}
...
...
data/1.算法初阶/1.蓝桥杯/分糖果/solution.md
浏览文件 @
3029e901
...
@@ -26,7 +26,8 @@
...
@@ -26,7 +26,8 @@
## aop
## aop
### before
### before
```
cpp
```
cpp
#include <iostream>
using
namespace
std
;
```
```
### after
### after
```
cpp
```
cpp
...
@@ -35,21 +36,182 @@
...
@@ -35,21 +36,182 @@
## 答案
## 答案
```
cpp
```
cpp
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
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
{
flag
=
false
;
break
;
}
}
if
(
flag
==
true
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
-
1
;
i
>=
0
;
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
;
}
}
}
cout
<<
total
<<
endl
;
}
```
```
## 选项
## 选项
### A
### A
```
cpp
```
cpp
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
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
{
flag
=
false
;
break
;
}
}
if
(
flag
==
true
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
;
i
>=
0
;
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
;
}
}
}
cout
<<
total
<<
endl
;
}
```
```
### B
### B
```
cpp
```
cpp
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
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
{
flag
=
false
;
break
;
}
}
if
(
flag
==
true
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
;
i
>=
0
;
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
;
}
}
}
cout
<<
total
<<
endl
;
}
```
```
### C
### C
```
cpp
```
cpp
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
)
{
bool
flag
=
true
;
for
(
int
i
=
1
;
i
<
n
;
i
++
)
{
if
(
Candy
[
0
]
!=
Candy
[
i
])
{
flag
=
false
;
break
;
}
}
if
(
flag
==
true
)
break
;
int
temp
=
Candy
[
n
-
1
];
for
(
int
i
=
n
-
1
;
i
>=
0
;
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
;
}
}
}
cout
<<
total
<<
endl
;
}
```
```
src/__pycache__/tree.cpython-38.pyc
浏览文件 @
3029e901
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录