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
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,16 @@
"__node_handle": "cpp",
"__verbose_abort": "cpp",
"execution": "cpp",
"print": "cpp"
"print": "cpp",
"filesystem": "cpp",
"format": "cpp",
"ccomplex": "cpp",
"cstdbool": "cpp",
"ctgmath": "cpp",
"__assert": "cpp",
"ranges": "cpp",
"version": "cpp",
"bit": "cpp"
},
"editor.mouseWheelZoom": true,
"workbench.tree.enableStickyScroll": true,
Expand Down
35 changes: 35 additions & 0 deletions Codes/1039-minimum-score-triangulation-of-polygon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* @Author: LetMeFly
* @Date: 2025-09-29 18:44:48
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-01 19:58:47
*/
#if defined(_WIN32) || defined(__APPLE__)
#include "_[1,2]toVector.h"
#endif

#if false // this doesn't work
// 相邻两点乘积的和 + (n-1)条边乘积的2倍
// 但是不能相交
// 诶,好像直接最小的那个去连其他所有剩下的就好了
class Solution {
public:
int minScoreTriangulation(vector<int>& values) {
int ans = values[0] * values.back();
int m = values[0], loc = 0;
for (int i = 1; i < values.size(); i++) {
ans += values[i - 1] * values[i];
if (values[i] < m) {
m = values[i];
loc = i;
}
}
for (int i = 0; i < values.size(); i++) {
if (abs(i - loc) > 1) {
ans += m * values[i] * 2;
}
}
return ans;
}
};
#endif
77 changes: 77 additions & 0 deletions Codes/1039-minimum-score-triangulation-of-polygon_Ok.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* @Author: LetMeFly
* @Date: 2025-09-29 18:44:48
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-10-01 20:38:27
*/
#if defined(_WIN32) || defined(__APPLE__)
#include "_[1,2]toVector.h"
#endif

class Solution {
private:
unordered_map<int, int> cache;
vector<int> values;
int n;

int dfs(int i, int j) {
if (j - i < 2) {
return 0;
}
int key = i * n + j;
if (cache.count(key)) {
return cache[key];
}
if (j - i == 2) {
return cache[key] = values[i] * values[i + 1] * values[i + 2];
}
int ans = 1000000000;
/*
0 1 2 3 -> 0 1 2 + 0 2 3

0 1

3 2


0 1 2 3 4


3

4 2

0 1


(i,j,k) + dfs(i,k)+dfs(k,j)
*/
for (int k = i + 1; k < j; k++) {
ans = min(ans, dfs(i, k) + dfs(k, j) + values[i] * values[k] * values[j]);
}
return cache[key] = ans;
}
public:
int minScoreTriangulation(vector<int>& values) {
this->values = move(values);
n = this->values.size();
return dfs(0, n - 1);
}
};

#if defined(_WIN32) || defined(__APPLE__)
/*
[3,7,4,5]

144
*/
int main() {
string s;
while (cin >> s) {
vector<int> v = stringToVector(s);
Solution sol;
cout << sol.minScoreTriangulation(v) << endl;
}
return 0;
}
#endif
2 changes: 1 addition & 1 deletion Codes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: LetMeFly
* @Date: 2025-08-07 14:11:36
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-09-07 23:24:39
* @LastEditTime: 2025-10-01 20:40:27
*/
pub struct Solution;
include!("0976-largest-perimeter-triangle.rs"); // 这个fileName是会被脚本替换掉的
25 changes: 25 additions & 0 deletions Codes/pinduoduo-01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'''
Author: LetMeFly
Date: 2025-09-28 19:01:34
LastEditors: LetMeFly.xyz
LastEditTime: 2025-09-28 19:06:41
'''
a = input()
if len(a) != 9:
print('Invalid')
exit(0)
for i in range(2):
if not 'A' <= a[i] <= 'Z':
print('Invalid')
exit(0)
for i in range(2, 8):
if not a[i].isdigit():
print('Invalid')
exit(0)
should = 0
for i in range(8):
should += ord(a[i])
should %= 26
should = chr(should + ord('A'))
a = a[:-1] + should
print(a)
118 changes: 118 additions & 0 deletions Codes/pinduoduo-02.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* @Author: LetMeFly
* @Date: 2025-09-28 19:10:08
* @LastEditors: LetMeFly.xyz
* @LastEditTime: 2025-09-28 19:31:14
*/
/*

1
2 3
0 1

2
3 1
0 2



root 1->2
times: 1
2->3: 1
need: 1
1 -> 2: 1
need: 1
3->1:
need: 3
times: 2
sum: 1+2=3
*/


/*

1
2 3
1 2 3 1


3
1 2
3 1 2 1

1->3: 2
times: 2
2->1: 4
times: 2
3->2: 4
times: 2
1->3: (5->3) 3
times: 3
2->1: (1->1) 0
3->2: (2->2) 0
1->1: (5->1) 1
times 1
sum: 2 + 2 + 2 + 3 + 1 = 10
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Node {
int original, to;
Node *left, *right;
int already; // 由于father导致的已变更次数
};

// 变化范围是1,2,3,4,5
inline int change(int original, int times) {
return (original + times - 1 + 5) % 5 + 1;
}

inline int calc(int from, int to) {
return (to - from + 5) % 5;
}

/*
5
1 2 3 0 1
2 3 1 0 2

*/

int main() {
int n;
cin >> n;
queue<Node*> q;
Node* head = new Node();
q.push(head);
for (int i = 0; i < n; i++) {
Node* thisNode = q.front();
q.pop();
cin >> thisNode->original;
thisNode->left = new Node();
thisNode->right = new Node();
q.push(thisNode->left);
q.push(thisNode->right);
}
q = queue<Node*>();
q.push(head);
ll ans = 0;
for (int i = 0; i < n; i++) {
Node* thisNode = q.front();
q.pop();
cin >> thisNode->to;
q.push(thisNode->left);
q.push(thisNode->right);
if (thisNode->original == 0) {
continue;
}
int from = change(thisNode->original, thisNode->already);
int need = calc(from, thisNode->to);
ans += need;
thisNode->left->already = (thisNode->already + need) % 5;
thisNode->right->already = (thisNode->already + need) % 5;
}
cout << ans << endl;
return 0;
}
Loading