Skip to content

Commit e41bef5

Browse files
committed
feat: 2022-06-26-huatai-FINTECH
1 parent 872851b commit e41bef5

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let input = ''
2+
3+
process.stdin.on('data', data => input += data)
4+
5+
process.stdin.on('end', () => {
6+
const cnt = input.split('\n')[0].split(' ').map(Number)
7+
let ans = 1e10
8+
const s = 'huatai'
9+
for (let ch of s) {
10+
let c = 0
11+
for (let i = 0; i < s.length; i++) if (s[i] === ch) c++
12+
let x = cnt[ch.charCodeAt(0) - 'a'.charCodeAt(0)]
13+
ans = Math.min(ans, Math.floor(x / c))
14+
}
15+
console.log(ans)
16+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
let input = ''
2+
3+
process.stdin.on('data', data => input += data)
4+
5+
process.stdin.on('end', () => {
6+
const lines = input.split('\n')
7+
const [n, k, x] = lines[0].split(' ').map(Number)
8+
const a = lines[1].split(' ').map(Number)
9+
const dp = []
10+
// 0: 不操作,1: 卖出,2: 买入
11+
dp[0] = [null, [x, 0], [0, 0]]
12+
for (let i = 1; i <= n; i++) {
13+
dp[i] = []
14+
let idx = -1, maxV = -1
15+
for (let j = 1; j < 3; j++) {
16+
const v = dp[i-1][j][0] * a[i-1] + dp[i-1][j][1]
17+
if(v > maxV) {
18+
idx = j
19+
maxV = v
20+
}
21+
}
22+
dp[i][1] = [0, maxV]
23+
let ck = Math.min(Math.floor(maxV / a[i-1]), k)
24+
dp[i][2] = [ck, maxV - a[i-1] * ck]
25+
}
26+
let ans = 0
27+
// console.log(dp)
28+
for (let j = 1; j < 3; j++) {
29+
const v = dp[n][j][0] * a[n-1] + dp[n][j][1]
30+
ans = Math.max(ans, v)
31+
}
32+
console.log(ans)
33+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
let input = ''
2+
3+
process.stdin.on('data', data => input += data)
4+
5+
process.stdin.on('end', () => {
6+
const lines = input.split('\n')
7+
const [n] = lines[0].split(' ').map(Number)
8+
const edges = lines.slice(1, n).map(line => line.split(' ').map(Number))
9+
const e = Array(n + 1).fill(0).map(() => [])
10+
for (const [x, y] of edges) {
11+
e[x].push(y)
12+
e[y].push(x)
13+
}
14+
const fa = Array(n + 1).fill(0).map((_, idx) => idx)
15+
const sz = Array(n + 1).fill(1)
16+
const get = (i) => {
17+
if (fa[i] === i) return i
18+
return fa[i] = get(fa[i])
19+
}
20+
const merge = (i, j) => {
21+
const fi = get(i); const fj = get(j)
22+
if (fi === fj) return
23+
const si = sz[fi]; const sj = sz[fj]
24+
if (si < sj) {
25+
fa[fi] = fj
26+
sz[fj] += si
27+
} else {
28+
fa[fj] = fi
29+
sz[fi] += sj
30+
}
31+
}
32+
let ans = 0; const P = (1e9 + 7)
33+
const Pn = BigInt(P)
34+
for (let i = 1; i <= n; i++) {
35+
let prod = 1n
36+
for (const j of e[i]) {
37+
if (j < i) {
38+
const fi = get(i); const fj = get(j)
39+
const sj = sz[fj]
40+
if (fi !== fj) {
41+
merge(i, j)
42+
ans += Number(BigInt(sj) * BigInt(i) * prod % Pn)
43+
ans %= P
44+
}
45+
prod += BigInt(sj)
46+
}
47+
}
48+
}
49+
console.log(ans)
50+
})

2022-online-assessments/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
- [2022-03-15-hulu](2022-03-15-hulu)
44
- [2022-04-24-tencent 腾讯实习前端笔试](2022-04-24-tencent)
5+
- [2022-06-26-huatai-FINTECH 华泰 FINTECH 竞赛](2022-06-26-huatai-FINTECH), [竞赛地址](https://competition.nowcoder.com/3/introduce), Rank 79

leetcode/contest-287/5302. Encrypt and Decrypt Strings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Encrypter.prototype.decrypt = function (word2) {
3838
for (let b = 0; b < d.length; b++) {
3939
const ch = d[b]
4040
const i = this.km[ch]
41+
if (i == null) {
42+
ok = false
43+
break
44+
}
4145
const p = this.values[i]
4246
for (let j = 0; j < p.length; j++) {
4347
if (p[j] === word2[idx]) idx++

0 commit comments

Comments
 (0)