Skip to content

Commit d78184c

Browse files
LetMeFly666Copilot
andauthored
update: 添加问题“1039.多边形三角剖分的最低得分”的代码和题解 (#1152)
* 1039: WA.cpp (#1151) + pdd 笔试 yesterday * words: today+yesterday | en(+jp) (#1151) * 1039: WA.cpp (#1151) * 1039: WA.cpp (#1151) * 1039: WA.cpp (#1151) * 1039: dbg.cpp (#1151) * 1039: AC.cpp (#1151) - AC,21.48%,23.47% * update: 添加问题“1039.多边形三角剖分的最低得分”的代码和题解 (#1152) 0976: AC.cpp+py+java+go+rust (#1149) cpp - AC,58.29%,26.60% rust - AC,-%,100.00% java - AC,96.37%,99.05% go - AC,47.06%,100.00% py - AC,34.41%,25.76% Signed-off-by: LetMeFly666 <[email protected]> * typo: Update Solutions/Other-Japanese-LearningNotes.md Co-authored-by: Copilot <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 9e51c1f commit d78184c

22 files changed

+1798
-3
lines changed

.vscode/settings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,16 @@
104104
"__node_handle": "cpp",
105105
"__verbose_abort": "cpp",
106106
"execution": "cpp",
107-
"print": "cpp"
107+
"print": "cpp",
108+
"filesystem": "cpp",
109+
"format": "cpp",
110+
"ccomplex": "cpp",
111+
"cstdbool": "cpp",
112+
"ctgmath": "cpp",
113+
"__assert": "cpp",
114+
"ranges": "cpp",
115+
"version": "cpp",
116+
"bit": "cpp"
108117
},
109118
"editor.mouseWheelZoom": true,
110119
"workbench.tree.enableStickyScroll": true,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-29 18:44:48
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-01 19:58:47
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
#if false // this doesn't work
12+
// 相邻两点乘积的和 + (n-1)条边乘积的2倍
13+
// 但是不能相交
14+
// 诶,好像直接最小的那个去连其他所有剩下的就好了
15+
class Solution {
16+
public:
17+
int minScoreTriangulation(vector<int>& values) {
18+
int ans = values[0] * values.back();
19+
int m = values[0], loc = 0;
20+
for (int i = 1; i < values.size(); i++) {
21+
ans += values[i - 1] * values[i];
22+
if (values[i] < m) {
23+
m = values[i];
24+
loc = i;
25+
}
26+
}
27+
for (int i = 0; i < values.size(); i++) {
28+
if (abs(i - loc) > 1) {
29+
ans += m * values[i] * 2;
30+
}
31+
}
32+
return ans;
33+
}
34+
};
35+
#endif
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-29 18:44:48
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-10-01 20:38:27
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
unordered_map<int, int> cache;
14+
vector<int> values;
15+
int n;
16+
17+
int dfs(int i, int j) {
18+
if (j - i < 2) {
19+
return 0;
20+
}
21+
int key = i * n + j;
22+
if (cache.count(key)) {
23+
return cache[key];
24+
}
25+
if (j - i == 2) {
26+
return cache[key] = values[i] * values[i + 1] * values[i + 2];
27+
}
28+
int ans = 1000000000;
29+
/*
30+
0 1 2 3 -> 0 1 2 + 0 2 3
31+
32+
0 1
33+
34+
3 2
35+
36+
37+
0 1 2 3 4
38+
39+
40+
3
41+
42+
4 2
43+
44+
0 1
45+
46+
47+
(i,j,k) + dfs(i,k)+dfs(k,j)
48+
*/
49+
for (int k = i + 1; k < j; k++) {
50+
ans = min(ans, dfs(i, k) + dfs(k, j) + values[i] * values[k] * values[j]);
51+
}
52+
return cache[key] = ans;
53+
}
54+
public:
55+
int minScoreTriangulation(vector<int>& values) {
56+
this->values = move(values);
57+
n = this->values.size();
58+
return dfs(0, n - 1);
59+
}
60+
};
61+
62+
#if defined(_WIN32) || defined(__APPLE__)
63+
/*
64+
[3,7,4,5]
65+
66+
144
67+
*/
68+
int main() {
69+
string s;
70+
while (cin >> s) {
71+
vector<int> v = stringToVector(s);
72+
Solution sol;
73+
cout << sol.minScoreTriangulation(v) << endl;
74+
}
75+
return 0;
76+
}
77+
#endif

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: LetMeFly
33
* @Date: 2025-08-07 14:11:36
44
* @LastEditors: LetMeFly.xyz
5-
* @LastEditTime: 2025-09-07 23:24:39
5+
* @LastEditTime: 2025-10-01 20:40:27
66
*/
77
pub struct Solution;
88
include!("0976-largest-perimeter-triangle.rs"); // 这个fileName是会被脚本替换掉的

Codes/pinduoduo-01.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-09-28 19:01:34
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-09-28 19:06:41
6+
'''
7+
a = input()
8+
if len(a) != 9:
9+
print('Invalid')
10+
exit(0)
11+
for i in range(2):
12+
if not 'A' <= a[i] <= 'Z':
13+
print('Invalid')
14+
exit(0)
15+
for i in range(2, 8):
16+
if not a[i].isdigit():
17+
print('Invalid')
18+
exit(0)
19+
should = 0
20+
for i in range(8):
21+
should += ord(a[i])
22+
should %= 26
23+
should = chr(should + ord('A'))
24+
a = a[:-1] + should
25+
print(a)

Codes/pinduoduo-02.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-09-28 19:10:08
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-09-28 19:31:14
6+
*/
7+
/*
8+
9+
1
10+
2 3
11+
0 1
12+
13+
2
14+
3 1
15+
0 2
16+
17+
18+
19+
root 1->2
20+
times: 1
21+
2->3: 1
22+
need: 1
23+
1 -> 2: 1
24+
need: 1
25+
3->1:
26+
need: 3
27+
times: 2
28+
sum: 1+2=3
29+
*/
30+
31+
32+
/*
33+
34+
1
35+
2 3
36+
1 2 3 1
37+
38+
39+
3
40+
1 2
41+
3 1 2 1
42+
43+
1->3: 2
44+
times: 2
45+
2->1: 4
46+
times: 2
47+
3->2: 4
48+
times: 2
49+
1->3: (5->3) 3
50+
times: 3
51+
2->1: (1->1) 0
52+
3->2: (2->2) 0
53+
1->1: (5->1) 1
54+
times 1
55+
sum: 2 + 2 + 2 + 3 + 1 = 10
56+
*/
57+
#include <bits/stdc++.h>
58+
using namespace std;
59+
typedef long long ll;
60+
61+
struct Node {
62+
int original, to;
63+
Node *left, *right;
64+
int already; // 由于father导致的已变更次数
65+
};
66+
67+
// 变化范围是1,2,3,4,5
68+
inline int change(int original, int times) {
69+
return (original + times - 1 + 5) % 5 + 1;
70+
}
71+
72+
inline int calc(int from, int to) {
73+
return (to - from + 5) % 5;
74+
}
75+
76+
/*
77+
5
78+
1 2 3 0 1
79+
2 3 1 0 2
80+
81+
*/
82+
83+
int main() {
84+
int n;
85+
cin >> n;
86+
queue<Node*> q;
87+
Node* head = new Node();
88+
q.push(head);
89+
for (int i = 0; i < n; i++) {
90+
Node* thisNode = q.front();
91+
q.pop();
92+
cin >> thisNode->original;
93+
thisNode->left = new Node();
94+
thisNode->right = new Node();
95+
q.push(thisNode->left);
96+
q.push(thisNode->right);
97+
}
98+
q = queue<Node*>();
99+
q.push(head);
100+
ll ans = 0;
101+
for (int i = 0; i < n; i++) {
102+
Node* thisNode = q.front();
103+
q.pop();
104+
cin >> thisNode->to;
105+
q.push(thisNode->left);
106+
q.push(thisNode->right);
107+
if (thisNode->original == 0) {
108+
continue;
109+
}
110+
int from = change(thisNode->original, thisNode->already);
111+
int need = calc(from, thisNode->to);
112+
ans += need;
113+
thisNode->left->already = (thisNode->already + need) % 5;
114+
thisNode->right->already = (thisNode->already + need) % 5;
115+
}
116+
cout << ans << endl;
117+
return 0;
118+
}

0 commit comments

Comments
 (0)