-
Notifications
You must be signed in to change notification settings - Fork 3
update: 添加问题“1039.多边形三角剖分的最低得分”的代码和题解 #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5448c27
1039: WA.cpp (#1151) + pdd 笔试 yesterday
LetMeFly666 a8c9972
words: today+yesterday | en(+jp) (#1151)
LetMeFly666 2879e97
1039: WA.cpp (#1151)
LetMeFly666 44a9c6f
1039: WA.cpp (#1151)
LetMeFly666 738623e
1039: WA.cpp (#1151)
LetMeFly666 e2c91b9
1039: dbg.cpp (#1151)
LetMeFly666 41293d4
1039: AC.cpp (#1151) - AC,21.48%,23.47%
LetMeFly666 61529b0
update: 添加问题“1039.多边形三角剖分的最低得分”的代码和题解 (#1152)
LetMeFly666 bc5f52d
typo: Update Solutions/Other-Japanese-LearningNotes.md
LetMeFly666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.