Skip to content

Commit d87d4ee

Browse files
committed
Remove outdated C++ and Python files from various problem sets and contests to improve project organization and maintainability.
1 parent 740a1a2 commit d87d4ee

141 files changed

Lines changed: 2705 additions & 1928 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def countPalindromicSubsequence(self, s: str) -> int:
3+
n = len(s)
4+
ans = 0
5+
for i in range(26):
6+
l,r = 0,n-1
7+
while l < n and ord(s[l]) - ord('a') != i:
8+
l += 1
9+
while r >= 0 and ord(s[r]) - ord('a') != i:
10+
r -= 1
11+
if r - l < 2:
12+
continue
13+
charset = set()
14+
for k in range(l+1,r):
15+
charset.add(s[k])
16+
ans += len(charset)
17+
return ans
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def countPalindromicSubsequence(self, s: str) -> int:
3+
n = len(s)
4+
res = 0
5+
# 枚举两侧字符
6+
for i in range(26):
7+
l, r = 0, n - 1
8+
# 寻找该字符第一次出现的下标
9+
while l < n and ord(s[l]) - ord('a') != i:
10+
l += 1
11+
# 寻找该字符最后一次出现的下标
12+
while r >= 0 and ord(s[r]) - ord('a') != i:
13+
r -= 1
14+
if r - l < 2:
15+
# 该字符未出现,或两下标中间的子串不存在
16+
continue
17+
# 利用哈希集合统计 s[l+1..r-1] 子串的字符总数,并更新答案
18+
charset = set()
19+
for k in range(l + 1, r):
20+
charset.add(s[k])
21+
res += len(charset)
22+
return res
23+
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#include <bits/stdc++.h> // 包含C++标准库
2-
3-
using namespace std;
4-
int a[2000000], n, m; // 定义数组a和变量n,m。n是范围上限,m是输入数的个数
5-
6-
int main()
7-
{
8-
cin >> n >> m; // 输入n和m
9-
for (int i = 0; i < m; i++)
10-
cin >> a[i]; // 循环读入m个数到数组a中
11-
12-
sort(a, a + m); // 使用sort函数对数组a中的m个数进行升序排序
13-
14-
for (int i = 0; i < m; i++)
15-
cout << a[i] << " "; // 循环输出排序后的m个数,每个数后面加空格
16-
return 0;
1+
#include <bits/stdc++.h> // 包含C++标准库
2+
3+
using namespace std;
4+
int a[2000000], n, m; // 定义数组a和变量n,m。n是范围上限,m是输入数的个数
5+
6+
int main()
7+
{
8+
cin >> n >> m; // 输入n和m
9+
for (int i = 0; i < m; i++)
10+
cin >> a[i]; // 循环读入m个数到数组a中
11+
12+
sort(a, a + m); // 使用sort函数对数组a中的m个数进行升序排序
13+
14+
for (int i = 0; i < m; i++)
15+
cout << a[i] << " "; // 循环输出排序后的m个数,每个数后面加空格
16+
return 0;
1717
}
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
#include <iostream>
2-
3-
using namespace std;
4-
5-
int main()
6-
{
7-
ios::sync_with_stdio(false);
8-
cin.tie(nullptr);
9-
10-
int n, m;
11-
cin >> n >> m;
12-
13-
// 使用计数排序,因为n是范围上限,所以开一个n+1大小的数组记录每个数出现的次数
14-
int count[2000001] = {0}; // 题目n最大为2000000
15-
16-
// 统计每个数出现的次数
17-
for (int i = 0; i < m; i++)
18-
{
19-
int x;
20-
cin >> x;
21-
count[x]++;
22-
}
23-
24-
// 按顺序输出
25-
for (int i = 1; i <= n; i++)
26-
{
27-
while (count[i]--)
28-
{
29-
cout << i << " ";
30-
}
31-
}
32-
33-
return 0;
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios::sync_with_stdio(false);
8+
cin.tie(nullptr);
9+
10+
int n, m;
11+
cin >> n >> m;
12+
13+
// 使用计数排序,因为n是范围上限,所以开一个n+1大小的数组记录每个数出现的次数
14+
int count[2000001] = {0}; // 题目n最大为2000000
15+
16+
// 统计每个数出现的次数
17+
for (int i = 0; i < m; i++)
18+
{
19+
int x;
20+
cin >> x;
21+
count[x]++;
22+
}
23+
24+
// 按顺序输出
25+
for (int i = 1; i <= n; i++)
26+
{
27+
while (count[i]--)
28+
{
29+
cout << i << " ";
30+
}
31+
}
32+
33+
return 0;
3434
}
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
#include <iostream>
2-
#include <vector>
3-
4-
using namespace std;
5-
6-
// 直接插入一个元素到已排序的数组中
7-
void insertElement(vector<int> &arr, int size, int element)
8-
{
9-
int j = size - 1;
10-
// 将比element大的元素都向后移动一位
11-
while (j >= 0 && arr[j] > element)
12-
{
13-
arr[j + 1] = arr[j];
14-
j--;
15-
}
16-
arr[j + 1] = element; // 插入element到正确位置
17-
}
18-
19-
int main()
20-
{
21-
ios::sync_with_stdio(false); // 优化输入输出
22-
cin.tie(nullptr);
23-
24-
int n, m;
25-
cin >> n >> m;
26-
vector<int> arr(m); // 使用vector存储数据
27-
28-
// 输入第一个数据
29-
cin >> arr[0];
30-
31-
// 边输入边排序
32-
for (int i = 1; i < m; i++)
33-
{
34-
int num;
35-
cin >> num;
36-
insertElement(arr, i, num);
37-
}
38-
39-
// 输出排序后的结果
40-
for (int i = 0; i < m; i++)
41-
{
42-
cout << arr[i] << " ";
43-
}
44-
cout << endl;
45-
46-
return 0;
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
// 直接插入一个元素到已排序的数组中
7+
void insertElement(vector<int> &arr, int size, int element)
8+
{
9+
int j = size - 1;
10+
// 将比element大的元素都向后移动一位
11+
while (j >= 0 && arr[j] > element)
12+
{
13+
arr[j + 1] = arr[j];
14+
j--;
15+
}
16+
arr[j + 1] = element; // 插入element到正确位置
17+
}
18+
19+
int main()
20+
{
21+
ios::sync_with_stdio(false); // 优化输入输出
22+
cin.tie(nullptr);
23+
24+
int n, m;
25+
cin >> n >> m;
26+
vector<int> arr(m); // 使用vector存储数据
27+
28+
// 输入第一个数据
29+
cin >> arr[0];
30+
31+
// 边输入边排序
32+
for (int i = 1; i < m; i++)
33+
{
34+
int num;
35+
cin >> num;
36+
insertElement(arr, i, num);
37+
}
38+
39+
// 输出排序后的结果
40+
for (int i = 0; i < m; i++)
41+
{
42+
cout << arr[i] << " ";
43+
}
44+
cout << endl;
45+
46+
return 0;
4747
}
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
#include <iostream>
2-
//DFS深度优先搜索
3-
4-
using namespace std;
5-
6-
string tot;
7-
int n, m;
8-
9-
// 将找到的方案转换为字符串形式并计数
10-
void leijia(int a)
11-
{
12-
int b = 262144;//表示处理到第10中配料
13-
while (a)
14-
{
15-
tot += to_string(a / b);
16-
tot += ' ';
17-
a %= b;
18-
b /= 4;
19-
}
20-
tot += '\n';
21-
m++;
22-
}
23-
24-
// 递归函数,寻找满足条件的方案
25-
void f(int s, int k)
26-
{
27-
if (s < 1 && k < 262145)
28-
return;
29-
if (s > 0 && k > 262144)
30-
return;
31-
if (s == 0 && k > 262144)
32-
{
33-
leijia(k);
34-
return;
35-
}
36-
f(s - 1, k * 4 + 1);//相当于在四进制末尾添加一个数字,记录每个配料的使用量
37-
f(s - 2, k * 4 + 2);
38-
f(s - 3, k * 4 + 3);
39-
}
40-
41-
int main()
42-
{
43-
cin >> n;
44-
f(n, 0);
45-
cout << m << endl << tot;
46-
return 0;
1+
#include <iostream>
2+
//DFS深度优先搜索
3+
4+
using namespace std;
5+
6+
string tot;
7+
int n, m;
8+
9+
// 将找到的方案转换为字符串形式并计数
10+
void leijia(int a)
11+
{
12+
int b = 262144;//表示处理到第10中配料
13+
while (a)
14+
{
15+
tot += to_string(a / b);
16+
tot += ' ';
17+
a %= b;
18+
b /= 4;
19+
}
20+
tot += '\n';
21+
m++;
22+
}
23+
24+
// 递归函数,寻找满足条件的方案
25+
void f(int s, int k)
26+
{
27+
if (s < 1 && k < 262145)
28+
return;
29+
if (s > 0 && k > 262144)
30+
return;
31+
if (s == 0 && k > 262144)
32+
{
33+
leijia(k);
34+
return;
35+
}
36+
f(s - 1, k * 4 + 1);//相当于在四进制末尾添加一个数字,记录每个配料的使用量
37+
f(s - 2, k * 4 + 2);
38+
f(s - 3, k * 4 + 3);
39+
}
40+
41+
int main()
42+
{
43+
cin >> n;
44+
f(n, 0);
45+
cout << m << endl << tot;
46+
return 0;
4747
}

luogu_code/algorithm/1-3_Brute Force/P2089/tempCodeRunnerFile.cpp renamed to luogu/algorithm/1-3_Brute Force/P2089/tempCodeRunnerFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# 读取输入,使用input()函数获取用户输入的字符串,并用split()方法将其分割成多个部分,再用map()函数将其转换为整数
2-
n, m = map(int, input().split())
3-
4-
# 初始化计数器,分别用于计数正方形和长方形的数量
5-
cnt_square = 0 # 正方形计数
6-
cnt_rectangle = 0 # 长方形计数
7-
8-
sum_all = (m +1) *m//2*(n+1)*n//2;
9-
for i in range(1, min(n,m)+1):
10-
cnt_square +=(m-i+1)*(n-i+1)
11-
cnt_rectangle = sum_all - cnt_square
12-
13-
# 输出结果,使用print()函数输出正方形和长方形的数量
1+
# 读取输入,使用input()函数获取用户输入的字符串,并用split()方法将其分割成多个部分,再用map()函数将其转换为整数
2+
n, m = map(int, input().split())
3+
4+
# 初始化计数器,分别用于计数正方形和长方形的数量
5+
cnt_square = 0 # 正方形计数
6+
cnt_rectangle = 0 # 长方形计数
7+
8+
sum_all = (m +1) *m//2*(n+1)*n//2;
9+
for i in range(1, min(n,m)+1):
10+
cnt_square +=(m-i+1)*(n-i+1)
11+
cnt_rectangle = sum_all - cnt_square
12+
13+
# 输出结果,使用print()函数输出正方形和长方形的数量
1414
print(cnt_square, cnt_rectangle)

0 commit comments

Comments
 (0)