Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@
"preLaunchTask": "C/C++: g++.exe 生成活动文件"
},
{
"name": "C/C++: clang++ 生成和调试活动文件",
"type": "cppdbg",
"name": "C/C++: clang++ debug",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ 生成活动文件"
"cwd": "${workspaceFolder}",
"preLaunchTask": "C/C++: clang++ build",
}
]
}
13 changes: 7 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"label": "C/C++: clang++ build",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
Expand All @@ -43,11 +43,12 @@
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。",
// "condition": {
// "os": "macos"
// }
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"

}
],
"version": "2.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @Author: LetMeFly
* @Date: 2025-10-21 18:51:21
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-30 22:53:20
*/
#if defined(_WIN32) || defined(__APPLE__)
#include "_[1,2]toVector.h"
#endif

class Solution {
public:
int maxFrequency(vector<int>& nums, int k, int numOperations) {
sort(nums.begin(), nums.end());
unordered_map<int, int> frequency;
for (int t : nums) {
frequency[t]++;
}
int ans = 0;
for (int l = 0, r = 0, target = nums[0]; target <= nums.back(); target++) {
while (target - nums[l] > k) {
l++;
}
while (r < nums.size() && nums[r] - target <= k) {
Comment thread
LetMeFly666 marked this conversation as resolved.
r++;
}
ans = max(ans, min(r - l, numOperations + frequency[target]));
}
return ans;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* @Author: LetMeFly
* @Date: 2025-10-30 22:39:36
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-30 23:00:59
*/
package main

import "sort"

func maxFrequency(nums []int, k int, numOperations int) (ans int) {
sort.Ints(nums)
frequency := map[int]int{}
for _, t := range nums {
frequency[t]++
}
n := len(nums)
for l, r, target := 0, 0, nums[0]; target <= nums[n - 1]; target++ {
for target - nums[l] > k {
l++
}
for r < n && nums[r] - target <= k {
r++
}
ans = max(ans, min(r - l, numOperations + frequency[target]))
}
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* @Author: LetMeFly
* @Date: 2025-10-30 22:39:36
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-30 23:07:34
*/
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;

class Solution {
public int maxFrequency(int[] nums, int k, int numOperations) {
Arrays.sort(nums);
Map<Integer, Integer> frequency = new HashMap<>();
for (int t : nums) {
frequency.merge(t, 1, Integer::sum); // 这个api挺容易忘的
}
int ans = 0, n = nums.length;
for (int l = 0, r = 0, target = nums[0]; target <= nums[n - 1]; target++) {
while (target - nums[l] > k) {
l++;
}
while (r < n && nums[r] - target <= k) {
r++;
}
ans = Math.max(ans, Math.min(r - l, numOperations + frequency.getOrDefault(target, 0)));
}
return ans;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
Author: LetMeFly
Date: 2025-10-30 22:39:36
LastEditors: LetMeFly.xyz
LastEditTime: 2025-10-30 22:57:07
'''
from typing import List
from collections import Counter

class Solution:
def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:
nums.sort()
frequency = Counter(nums)
l = r = 0
ans = 0
for target in range(nums[0], nums[-1] + 1):
while target - nums[l] > k:
l += 1
while r < len(nums) and nums[r] - target <= k:
r += 1
ans = max(ans, min(r - l, numOperations + frequency[target]))
return ans # 刚刚差点忘记return
Comment thread
LetMeFly666 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @Author: LetMeFly
* @Date: 2025-10-30 22:39:36
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-30 23:19:32
*/
use std::collections::HashMap;
// 这台机器上没有安装过rust,故无IDE语法检查了
Comment thread
LetMeFly666 marked this conversation as resolved.
impl Solution {
pub fn max_frequency(mut nums: Vec<i32>, k: i32, num_operations: i32) -> i32 {
nums.sort();
let mut frequency = HashMap::new();
for &t in &nums {
*frequency.entry(t).or_insert(0) += 1; // 不存在时默认值为0
}

let mut ans: i32 = 0;
let mut l: usize = 0;
let mut r: usize = 0;
for target in nums[0]..=nums[nums.len()-1] {
while target - nums[l] > k {
l += 1;
}
while r < nums.len() && nums[r] - target <= k {
r += 1;
}
ans = ans.max(((r - l) as i32).min(num_operations + *frequency.get(&target).unwrap_or(&0)));
}
ans
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: LetMeFly
* @Date: 2025-10-23 23:05:13
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-23 23:32:07
* @LastEditTime: 2025-10-24 14:21:02
*/
package main

Expand All @@ -12,7 +12,7 @@ func hasSameDigits(s string) bool {
a[i] = s[i] - '0'
}
for len(a) > 2 {
b := make([]byte,len(a) - 1)
b := make([]byte, len(a) - 1)
for i := range b {
b[i] = (a[i] + a[i + 1]) % 10
}
Expand Down
93 changes: 93 additions & 0 deletions Codes/huawei2025Autumn-01-AC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'''
Author: LetMeFly
Date: 2025-10-29 19:30:11
LastEditors: LetMeFly.xyz
LastEditTime: 2025-10-29 20:04:49
'''
"""
6 10
20 10 -1
10 21 -1
21 -1 11
11 -1 22
22 12 -1
12 -1 -1
"""
from collections import defaultdict

class Node:
def __init__(self, val: int):
self.val = val
self.left = None
self.right = None
self.isRoot = True

ma = defaultdict(Node)

def getNode(val: int) -> Node:
if val == -1:
return None
if val in ma:
return ma[val]
ans = Node(val)
ma[val] = ans
return ans

# 其实这里返回Node也可以
def getRoot() -> int:
Comment thread
LetMeFly666 marked this conversation as resolved.
for val, node in ma.items():
# print(val, node)
if node.isRoot:
return val

n, k = map(int, input().split())

for _ in range(n):
root, l, r = map(getNode, map(int, input().split()))
# print(root.val, l.val, r.val)
root.left = l
root.right = r
if l:
l.isRoot = False
if r:
r.isRoot = False

root = getRoot()
# print(root)

ans = 0

"""
status:
0 无状态
1 刚递增过
2 刚递减过
"""
def dfs(root: Node, cnt: int, parent: Node, status: int):
global ans
ans = max(ans, cnt)
if not root:
return

nextStatus = 0
if status == 1 and parent.val - root.val >= k:
cnt += 1
nextStatus = 2
if status == 2 and root.val - parent.val >= k:
cnt += 1
nextStatus = 1
if not nextStatus:
cnt = 1
if parent and parent.val - root.val >= k:
cnt += 1
nextStatus = 2
if parent and root.val - parent.val >= k:
cnt += 1
nextStatus = 1
dfs(root.left, cnt, root, nextStatus)
dfs(root.right, cnt, root, nextStatus)


dfs(ma[root], 0, None, 0)

print(ans)
57 changes: 57 additions & 0 deletions Codes/huawei2025Autumn-02-BaoLi-WA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''
Author: LetMeFly
Date: 2025-10-29 20:05:25
LastEditors: LetMeFly.xyz
LastEditTime: 2025-10-29 20:59:46
'''
"""
dp[i][j]:重量i价值j最少车数


5
80
30 45 15 15 80
400 470 200 200 870
"""

n = int(input())
k = int(input())
weights = list(map(int, input().split()))
values = list(map(int, input().split()))

dp = [[0] * (n * 1000) for _ in range(n)]
maxVal = 0
ans = []
status = 1 << n
for i in range(status):
thisW = thisV = 0
thisChoosen = []
for j in range(n):
if i & (1 << j):
thisW += weights[j]
thisV += values[j]
thisChoosen.append(j)
if thisW > k:
break
if thisW > k:
break
if thisW <= k:
if thisV > maxVal or (thisV == maxVal and len(thisChoosen) < len(ans)):
# if thisV > maxVal:
ans = thisChoosen
maxV = thisV
Comment thread
LetMeFly666 marked this conversation as resolved.
Comment thread
LetMeFly666 marked this conversation as resolved.

if not len(ans):
print(-1)
else:
ans.sort()
for i, v in enumerate(ans):
# print(v, end=' ')
if i:
print(' ', end='')
print(v, end='')


# """
# dfs(i)
# """
18 changes: 18 additions & 0 deletions Codes/huawei2025Autumn-03-WA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''
Author: LetMeFly
Date: 2025-10-29 20:35:05
LastEditors: LetMeFly.xyz
LastEditTime: 2025-10-29 20:49:47
'''
"""
10
448 0 112 0 0 0 28 260 3 0



n(最多10^6)个非负整数(0到10^18),两个数之间与不为0则有边,求最短环(长度不小于3)的长度,若无输出-1
"""

import random
random.seed(9333)
print(random.choice([-1, 3, 4]))
Loading