Skip to content

Commit 8bd169a

Browse files
committed
2 parents 21de68e + dd58193 commit 8bd169a

11 files changed

Lines changed: 350 additions & 2 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vs
2-
.vscode
2+
.vscode/*
3+
!.vscode/*.code-snippets
34
.cache/
45
*.exe
56
.cph

.vscode/markdown.code-snippets

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"题解框架": {
3+
"scope": "markdown",
4+
"prefix": "ac",
5+
"body": [
6+
"# ${1:题目名称}",
7+
"",
8+
"## 题目描述",
9+
"",
10+
"## 思路",
11+
"",
12+
"- 时间复杂度:${2:O(n)}",
13+
"- 空间复杂度:${3:O(1)}",
14+
"",
15+
"### 代码",
16+
"",
17+
"```cpp",
18+
"$0",
19+
"```"
20+
],
21+
"description": "Markdown 题解框架"
22+
}
23+
}

.vscode/tkcpp.code-snippets

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"tkcpp": {
3+
"prefix": ["tkcpp"],
4+
"description": "C++ 快速模板(竞赛/练习)",
5+
"scope": "cpp",
6+
"body": [
7+
"#include <bits/stdc++.h>",
8+
"using namespace std;",
9+
"",
10+
"int main() {",
11+
" ios::sync_with_stdio(false);",
12+
" cin.tie(nullptr);",
13+
"",
14+
" $0",
15+
"",
16+
" return 0;",
17+
"}"
18+
]
19+
},
20+
"tkpy": {
21+
"prefix": ["tkpy"],
22+
"description": "Python 竞赛快速模板",
23+
"scope": "python",
24+
"body": [
25+
"import sys",
26+
"from collections import defaultdict, deque, Counter",
27+
"from heapq import heappush, heappop",
28+
"from bisect import bisect_left, bisect_right",
29+
"from itertools import permutations, combinations",
30+
"from math import gcd, lcm, sqrt, ceil, floor",
31+
"",
32+
"input = sys.stdin.readline",
33+
"",
34+
"def solve():",
35+
" $0",
36+
" pass",
37+
"",
38+
"def main():",
39+
" # t = int(input())",
40+
" # for _ in range(t):",
41+
" # solve()",
42+
" solve()",
43+
"",
44+
"if __name__ == \"__main__\":",
45+
" main()"
46+
]
47+
},
48+
"tkpy_basic": {
49+
"prefix": ["tkpy_basic"],
50+
"description": "Python 基础模板",
51+
"scope": "python",
52+
"body": [
53+
"def solve():",
54+
" $0",
55+
" pass",
56+
"",
57+
"if __name__ == \"__main__\":",
58+
" solve()"
59+
]
60+
}
61+
}

acwing/problems/3213.数字排序.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<!--
2+
* @Author: tkzzzzzz6
3+
* @Date: 2026-05-18 11:10:00
4+
* @LastEditors: tkzzzzzz6
5+
* @LastEditTime: 2026-05-21 11:01:20
6+
-->
17
# 2. 数字排序
28

39
## 题目描述
@@ -9,7 +15,6 @@
915
1. 使用一个数组 `cnt` 来统计每个整数出现的次数,数组的索引表示整数的值,数组的值表示该整数出现的次数。
1016
2. 定义一个结构体 `Data` 来存储整数的值和出现次数,并重载 `<` 运算符以便按照出现次数从大到小排序,如果出现次数相同,则按照整数的大小从小到大排序。
1117
3. 将统计结果存储在一个数组 `q` 中,并对该数组进行排序。
12-
4. 最后输出排序后的结果。
1318

1419
```cpp
1520
#include <iostream>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* @Author: tkzzzzzz6
3+
* @Date: 2026-05-20 22:03:31
4+
* @LastEditors: tkzzzzzz6
5+
* @LastEditTime: 2026-05-20 22:14:34
6+
*/
7+
/*
8+
* @acwing app=acwing.cn id=5722 lang=C++
9+
*
10+
* 5719. 词频统计
11+
*/
12+
13+
// @acwing code start
14+
#include <iostream>
15+
#include <cstring>
16+
#include <algorithm>
17+
18+
using namespace std;
19+
20+
const int N = 110;
21+
22+
int cnt[N],tot[N]; //分别用来存储单词在多少篇文章中出现过以及在所有文章中总出现次数
23+
bool st[N]; // 用来判断单词在当前文章中是否出现过
24+
25+
26+
int main(){
27+
28+
int n,m;
29+
cin >> n >> m;
30+
31+
while(n--){
32+
int k;
33+
cin >> k;
34+
35+
memset(st,false,sizeof(st));
36+
while(k--){
37+
int x;
38+
cin >> x;
39+
tot[x]++;
40+
if(!st[x])
41+
{
42+
cnt[x]++;
43+
st[x] = true;
44+
}
45+
}
46+
}
47+
48+
for(int i = 1;i<=m;++i){
49+
cout << cnt[i] << ' ' << tot[i] << endl;
50+
}
51+
52+
return 0;
53+
}
54+
55+
// @acwing code end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# 1. 词频统计
2+
3+
## 题目描述
4+
5+
`m` 个单词,`n` 篇文章,每篇文章包含若干单词。统计每个单词在多少篇文章中出现过,以及在所有文章中总出现次数。
6+
7+
8+
## 思路
9+
10+
使用数组 `cnt` 来统计每个单词在多少篇文章中出现过,使用数组 `tot` 来统计每个单词在所有文章中总出现次数,布尔数组 `st` 来记录单词在当前文章中是否出现过。
11+
12+
最后输出每个单词的cnt和tot即可。
13+
14+
- 时间复杂度:O(n)
15+
- 空间复杂度:O(n)
16+
17+
### 代码
18+
19+
```cpp
20+
#include <iostream>
21+
#include <cstring>
22+
#include <algorithm>
23+
24+
using namespace std;
25+
26+
const int N = 110;
27+
28+
int cnt[N],tot[N]; //分别用来存储单词在多少篇文章中出现过以及在所有文章中总出现次数
29+
bool st[N]; // 用来判断单词在当前文章中是否出现过
30+
31+
32+
int main(){
33+
34+
int n,m;
35+
cin >> n >> m;
36+
37+
while(n--){
38+
int k;
39+
cin >> k;
40+
41+
memset(st,false,sizeof(st)); //注意每篇文章都要重置st数组,因为我们需要统计每篇文章中单词是否出现过
42+
while(k--){
43+
int x;
44+
cin >> x;
45+
tot[x]++;
46+
if(!st[x])
47+
{
48+
cnt[x]++;
49+
st[x] = true;
50+
}
51+
}
52+
}
53+
54+
for(int i = 1;i<=m;++i){
55+
cout << cnt[i] << ' ' << tot[i] << endl;
56+
}
57+
58+
return 0;
59+
}
60+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @acwing app=acwing.cn id=5723 lang=C++
3+
*
4+
* 5720. 相似度计算
5+
*/
6+
7+
// @acwing code start
8+
#include <iostream>
9+
#include <cstring>
10+
#include <unordered_set>
11+
#include <algorithm>
12+
13+
using namespace std;
14+
15+
unordered_set<string> a,b,c; //用来保存两篇文章的单词数量以及a∪b的单词数量
16+
17+
int main(){
18+
19+
int n,m;
20+
cin >> n >> m;
21+
22+
string s;
23+
for(int i = 0;i<n;++i)
24+
{
25+
cin >> s;
26+
for(auto &c:s)c = tolower(c);
27+
a.insert(s);
28+
c.insert(s);
29+
}
30+
31+
for(int i = 0;i<m;++i)
32+
{
33+
cin >> s;
34+
for(auto &c:s)c = tolower(c);
35+
b.insert(s);
36+
c.insert(s);
37+
}
38+
39+
cout << a.size() + b.size() - c.size() << '\n'; // 容斥原理,a∩b = a + b - a∪b
40+
cout << c.size() << '\n';
41+
42+
return 0;
43+
}
44+
45+
// @acwing code end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# 2. 相似度计算
2+
3+
## 题目描述
4+
5+
两个集合的 Jaccard 相似度定义为:
6+
7+
$$Sim(A,B) = \frac{|A \cap B|}{|A \cup B|}$$
8+
9+
给出两篇文章,每篇文章由若干单词组成,单词之间用空格分隔,单词由大小写字母组成,大小写字母视为同一个字母,隔行输出:
10+
11+
- 两篇文章中出现单词的交集和并集的大小.
12+
13+
## 思路
14+
15+
- 时间复杂度:O(n*logn)
16+
- 空间复杂度:O(n)
17+
18+
使用unordered_set来保存两篇文章的单词数量以及a∪b的单词数量,最后根据容斥原理计算出`a∩b`的大小以及`a∪b`的大小即可.
19+
20+
这里可以使用容斥原理求解 a∩b的大小:
21+
$$ a∩b = a + b - a∪b $$
22+
23+
### 代码
24+
25+
26+
27+
```cpp
28+
#include <iostream>
29+
#include <cstring>
30+
#include <unordered_set>
31+
#include <algorithm>
32+
33+
using namespace std;
34+
35+
unordered_set<string> a,b,c; //用来保存两篇文章的单词数量以及a∪b的单词数量
36+
37+
int main(){
38+
39+
int n,m;
40+
cin >> n >> m;
41+
42+
string s;
43+
for(int i = 0;i<n;++i)
44+
{
45+
cin >> s;
46+
for(auto &c:s)c = tolower(c);
47+
a.insert(s);
48+
c.insert(s);
49+
}
50+
51+
for(int i = 0;i<m;++i)
52+
{
53+
cin >> s;
54+
for(auto &c:s)c = tolower(c);
55+
b.insert(s);
56+
c.insert(s);
57+
}
58+
59+
cout << a.size() + b.size() - c.size() << '\n'; // 容斥原理,a∩b = a + b - a∪b
60+
cout << c.size() << '\n';
61+
62+
return 0;
63+
}
64+
```

acwing/problems/5722.十滴水.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* @acwing app=acwing.cn id=5725 lang=C++
3+
*
4+
* 5722. 十滴水
5+
*/
6+
7+
// @acwing code start
8+
9+
10+
// @acwing code end

acwing/problems/5722.十滴水.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 4.十滴水
2+
3+
## 题目描述
4+
5+
## 思路
6+
7+
双链表
8+
9+
- 时间复杂度:O(n)
10+
- 空间复杂度:O(1)
11+
12+
### 代码
13+
14+
```cpp
15+
16+
```

0 commit comments

Comments
 (0)