This commit is contained in:
2026-07-24 13:46:36 +08:00
parent 536a697566
commit 2b6dc69bde
7 changed files with 305 additions and 36 deletions
-2
View File
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CIDR" type="CPP_MODULE" version="4" />
+40 -34
View File
@@ -10,26 +10,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="4491295e-723c-4e0b-b7b4-9be1cbde5db8" name="更改" comment="">
<change afterPath="$PROJECT_DIR$/.idea/editor.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/luogu_ez_B3628.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_E01003.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_E01218.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_E02883.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_M01002.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_M02692.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/CodeEpiphany/challenges.db" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/CodeEpiphany/luogu.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/MarsCodeWorkspaceAppSettings.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/MarsCodeWorkspaceAppSettings.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/codeStyles/Project.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/codeStyles/codeStyleConfig.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/exercises@1.iml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/pyProjectModel.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/lc_127.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_M01017_6_boxes.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_M02692_12_coins.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pojcs101_M02692_12_coins_WRONG.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/exercises.iml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pojcs101_M01002.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/pojcs101_M01002_memorable_number.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -67,14 +54,17 @@
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"C/C++ 文件.D_pojcs101_M02692.cpp.executor": "Run",
"C/C++ 文件.luogu_UVA755.cpp.executor": "Run",
"C/C++ 文件.luogu_ez_B3628.cpp.executor": "Run",
"C/C++ 文件.ojcs101_E01003.cpp.executor": "Run",
"C/C++ 文件.ojcs101_E01218.cpp.executor": "Run",
"C/C++ 文件.ojcs101_E02883.cpp.executor": "Run",
"C/C++ 文件.pojcs101_M01017_6_boxes.cpp.executor": "Run",
"C/C++ 文件.pojcs101_M02692.cpp.executor": "Run",
"CidrDebugProfileConversion": "true",
"ModuleVcsDetector.initialDetectionPerformed": "true",
"Python.lc_127.executor": "Run",
"RunOnceActivity.RadMigrateCodeStyle": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
@@ -84,20 +74,23 @@
"cidr.known.project.marker": "true",
"codeWithMe.voiceChat.enabledByDefault": "false",
"git-widget-placeholder": "main",
"last_opened_file_path": "E:/Projects/exercises",
"node.js.detected.package.jshint": "true",
"node.js.selected.package.jshint": "",
"nodejs_package_manager_path": "npm",
"org.rust.first.attach.projects": "true",
"settings.editor.selected.configurable": "preferences.sourceCode.C++"
}
}]]></component>
<component name="RunManager" selected="C/C++ 文件.pojcs101_M02692.cpp">
<configuration name="luogu_UVA755.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="luogu_UVA755.cpp" CONFIG_NAME="luogu_UVA755.cpp">
<option name="sourceFile" value="luogu_UVA755.cpp" />
<component name="RunManager" selected="C/C++ 文件.pojcs101_M01017_6_boxes.cpp">
<configuration name="D_pojcs101_M02692.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="D_pojcs101_M02692.cpp" CONFIG_NAME="D_pojcs101_M02692.cpp">
<option name="sourceFile" value="D_pojcs101_M02692.cpp" />
<method v="2">
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="luogu_ez_B3628.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="luogu_ez_B3628.cpp" CONFIG_NAME="luogu_ez_B3628.cpp">
<option name="sourceFile" value="luogu_ez_B3628.cpp" />
<configuration name="luogu_UVA755.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="luogu_UVA755.cpp" CONFIG_NAME="luogu_UVA755.cpp">
<option name="sourceFile" value="luogu_UVA755.cpp" />
<method v="2">
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
</method>
@@ -114,21 +107,26 @@
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="pojcs101_M01017_6_boxes.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="pojcs101_M01017_6_boxes.cpp" CONFIG_NAME="pojcs101_M01017_6_boxes.cpp">
<option name="sourceFile" value="pojcs101_M01017_6_boxes.cpp" />
<method v="2">
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="pojcs101_M02692.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" temporary="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="exercises" TARGET_NAME="pojcs101_M02692.cpp" CONFIG_NAME="pojcs101_M02692.cpp">
<option name="sourceFile" value="pojcs101_M02692.cpp" />
<method v="2">
<option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="C/C++ 文件.pojcs101_M02692.cpp" />
<item itemvalue="C/C++ 文件.luogu_UVA755.cpp" />
<item itemvalue="C/C++ 文件.luogu_ez_B3628.cpp" />
<item itemvalue="C/C++ 文件.ojcs101_E02883.cpp" />
<item itemvalue="C/C++ 文件.ojcs101_E01218.cpp" />
</list>
</recent_temporary>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-js-predefined-d6986cc7102b-4abd2a77f808-JavaScript-PY-262.8665.309" />
<option value="bundled-python-sdk-c6d794e1806d-5bd6d13a2a75-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-262.8665.309" />
</set>
</attachedChunks>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="默认任务">
@@ -137,14 +135,22 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1784800801763</updated>
<workItem from="1784856532675" duration="4766000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="1" />
<option name="LAST_COMMIT_MESSAGE" value="1" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />
<select />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/exercises$lc_127.coverage" NAME="lc_127 覆盖结果" MODIFIED="1784859593317" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>
+42
View File
@@ -0,0 +1,42 @@
import sys
class Solution:
def __init__(self):
self.number_set: set[int] = set() # 哈希表,全 O(1)
self.longest_length: int = 1
def longestConsecutive(self, nums: list[int]) -> int:
if not nums: return 0
self.number_set = set(nums) # O(n)
for n in self.number_set:
# n = self.number_set.pop()
# print(n, file=sys.stderr)
current_length: int = 1
if n + 1 in self.number_set:
continue
# pointer = n
# while True:
# if pointer + 1 in self.number_set:
# pointer += 1
# current_length += 1
# self.number_set.remove(pointer)
# else:
# break
pointer = n
while True:
if pointer - 1 in self.number_set:
pointer -= 1
current_length += 1
# self.number_set.remove(pointer)
else:
break
self.longest_length = max(current_length, self.longest_length)
return self.longest_length
if __name__ == '__main__':
sol = Solution()
print(sol.longestConsecutive([100, 4, 200, 1, 3, 2]))
print(sol.longestConsecutive([0, 3, 7, 2, 5, 8, 4, 6, 0, 1]))
+78
View File
@@ -0,0 +1,78 @@
#include <iostream>
#include <vector>
using namespace std;
int package_requirement(vector<int> box_counts) {
int answer = box_counts[5] + box_counts[4] + box_counts[3];
// 5x5
box_counts[0] -= min(box_counts[4] * 11, box_counts[0]);
// 4x4
box_counts[1] -= box_counts[3] * 5;
if (box_counts[1] < 0) {
// 放 1x1
box_counts[0] -= min(-box_counts[1] * 4, box_counts[0]);
box_counts[1] = 0;
}
// 3x3
if (box_counts[2]) {
answer += (box_counts[2] - 1) / 4 + 1;
switch (4 - box_counts[2] % 4) {
case 4: break;
case 1:
box_counts[1]--;
box_counts[0] -= min(5, box_counts[0]);;
// if (box_counts[1]) {
// box_counts[1]--;
// box_counts[0] -= min(5, box_counts[0]);;
// } else {
// box_counts[0] -= min(9, box_counts[0]);
// }
break;
case 2:
box_counts[1] -= 3;
box_counts[0] -= min(6, box_counts[0]);
break;
case 3:
box_counts[1] -= 5;
box_counts[0] -= min(7, box_counts[0]);
break;
default:
throw logic_error("remaining_3x3_areas must be 4(0), 1, 2, or 3");
}
if (box_counts[1] < 0) {
// 放 1x1
box_counts[0] -= min(-box_counts[1] * 4, box_counts[0]);
box_counts[1] = 0;
}
}
// 2x2
if (box_counts[1]) {
answer += (box_counts[1] - 1) / 9 + 1;
int remaining_2x2_areas = 9 - box_counts[1] % 9;
if (remaining_2x2_areas == 9) { remaining_2x2_areas = 0; }
box_counts[0] -= min(remaining_2x2_areas * 4, box_counts[0]);
}
// 1x1
if (box_counts[0]) {
answer += (box_counts[0] - 1) / 36 + 1;
}
return answer;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<int> box_counts(6);
for (;;) {
cin >> box_counts[0] >> box_counts[1] >> box_counts[2] >> box_counts[3] >> box_counts[4] >> box_counts[5];
if (box_counts[0] == 0 && box_counts[1] == 0 && box_counts[2] == 0 && box_counts[3] == 0 && box_counts[4] == 0
&& box_counts[5] == 0) {
break;
}
cout << package_requirement(box_counts) << endl;
}
return 0;
}
+65
View File
@@ -0,0 +1,65 @@
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
void solveGroup() {
bool tempList[12] = {false};
bool realCoins[12] = {false};
vector<pair<string, string> > lighterResults;
for (int _ = 0; _ < 3; _++) {
string s1, s2, comparison;
cin >> s1 >> s2 >> comparison;
if (comparison == "even") {
for (const char c: s1 + s2) {
realCoins[c - 'A'] = true;
}
} else {
memset(tempList, false, sizeof(tempList));
for (const char c: s1 + s2) { tempList[c - 'A'] = true; }
for (int i = 0; i < 12; i++) {
if (!tempList[i]) { realCoins[i] = true; }
}
if (comparison == "down") {
lighterResults.emplace_back(s2, s1);
} else {
lighterResults.emplace_back(s1, s2);
}
}
}
for (int i = 0; i < 12; i++) {
if (realCoins[i]) continue;
int conclusion = 0;
for (const auto &[s1, s2]: lighterResults) {
if (s1.find(static_cast<char>(i + 'A')) != string::npos) {
if (conclusion == 1) {
conclusion = -2;
break;
}
conclusion = -1;
} else if (s2.find(static_cast<char>(i + 'A')) != string::npos) {
if (conclusion == -1) {
conclusion = -2;
break;
}
conclusion = 1;
}
}
if (conclusion == -2 || conclusion == 0) { continue; }
cout << static_cast<char>(i + 'A') << " is the counterfeit coin and it is "
<< (conclusion == 1 ? "light." : "heavy.") << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int _ = 0; _ < n; _++) {
solveGroup();
}
return 0;
}
+80
View File
@@ -0,0 +1,80 @@
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
void solveGroup() {
int fakeValue[12] = {};
bool tempList[12] = {false};
// int realCount = 0;
vector<pair<string, string> > lighterResults;
for (int _ = 0; _ < 3; _++) {
string s1, s2, comparison;
cin >> s1 >> s2 >> comparison;
memset(tempList, false, sizeof(tempList));
if (comparison == "even") {
// 八个都是真的
for (const char c: s1 + s2) {
tempList[c - 'A'] = true;
fakeValue[c - 'A'] -= 120;
}
for (int i = 0; i < 12; i++) {
if (!tempList[i]) { fakeValue[i]++; }
}
} else {
// 剩下四个是真的
for (const char c: s1 + s2) {
tempList[c - 'A'] = true;
fakeValue[c - 'A']++;
}
for (int i = 0; i < 12; i++) {
if (!tempList[i]) { fakeValue[i] -= 120; }
}
// 不着急比
if (comparison == "down") {
lighterResults.emplace_back(s2, s1);
} else {
lighterResults.emplace_back(s1, s2);
}
}
for (const int val: fakeValue) {
clog << val << endl;
}
}
int theFakeOne = -1, maxFakeVal = -120;
for (int i = 0; i < 12; i++) {
if (fakeValue[i] > maxFakeVal) {
maxFakeVal = fakeValue[i];
theFakeOne = i;
}
}
for (const auto &[s1, s2]: lighterResults) {
for (const char c: s1) {
if (c == 'A' + theFakeOne) {
cout << static_cast<char>(theFakeOne + 'A') << " is the counterfeit coin and it is heavy." << endl;
return;
}
}
for (const char c: s2) {
if (c == 'A' + theFakeOne) {
cout << static_cast<char>(theFakeOne + 'A') << " is the counterfeit coin and it is light." << endl;
return;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int _ = 0; _ < n; _++) {
solveGroup();
}
return 0;
}