1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| #include "word.h" #include <stdio.h> #include <string.h> #include <assert.h> #include <Windows.h> #include <cstdlib> #include <random> #include <algorithm>
using namespace std;
constexpr int dT = 20; constexpr int T = 10000; static const int NUM_SCRAMBLE = 8869; static const char SCRAMBLE[8869 * 5 + 1] = ; static const int win_points[5] = {85, 90, 100, 120, 150};
int judge(int T) { init(NUM_SCRAMBLE, SCRAMBLE); bool gold[5], silver[5]; mt19937_64 mt(random_device{}()); uniform_int_distribution<int> ud(0, NUM_SCRAMBLE - 1); int total_score = 0; for (int i = 1; i <= T; i++) { int answer = ud(mt); char init_letter = SCRAMBLE[answer * 5]; const char *guess_word = guess(i, 5, init_letter, gold, silver); for (int j = 4; j >= 0; j--) { if (strlen(guess_word) != 5) { break; } bool correct = true; for (int k = 0; k < 5; k++) { gold[k] = guess_word[k] == SCRAMBLE[answer * 5 + k]; if (!gold[k]) correct = false; } bool is_valid_guess = false; for (int l = 0; l < NUM_SCRAMBLE; l++) { bool same = true; for (int k = 0; k < 5; k++) { if (guess_word[k] != SCRAMBLE[l * 5 + k]) { same = false; break; } } if (same) { is_valid_guess = true; break; } } if (!is_valid_guess) { break; } if (correct) { total_score += win_points[j]; break; } if (j == 0) { break; } for (int k = 0; k < 5; k++) { silver[k] = false; for (int l = 0; l < 5; l++) if (!gold[k] && !gold[l] && guess_word[k] == SCRAMBLE[answer * 5 + l]) silver[k] = true; } guess_word = guess(i, j, init_letter, gold, silver); } } return total_score; }
PROCESS_INFORMATION pis[dT + 5]; int *anss[dT + 5]; HANDLE pbd[dT + 5]; char exe_path[256];
int main(int argc, char *argv[]) { if(argc == 1) { GetModuleFileName(NULL, exe_path, 256); for(int i=1;i<=dT;i++) { *(anss[i] = (int*)MapViewOfFile(pbd[i] = CreateFileMappingA(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,4,(string("OhYeahMyDeskmateUniformAKedIOIButIGot100PointsInNOIP2025") + to_string(i)).c_str()),FILE_MAP_ALL_ACCESS,0,0,4)) = 0; STARTUPINFO si = {sizeof si}; char *cmdLn = new char[256]; strcpy(cmdLn, string(string("\"") + exe_path + "\" " + to_string(i)).c_str()); CreateProcess(NULL, cmdLn, NULL, NULL, FALSE, 0, NULL, NULL, &si, pis + i); delete [] cmdLn; } int total_score = 0; for(int i=1;i<=dT;i++) { WaitForSingleObject(pis[i].hProcess, INFINITE); total_score += *anss[i]; UnmapViewOfFile(anss[i]); CloseHandle(pbd[i]); } printf("Total score: %d\n", total_score); double final_score = total_score * 1.0 / T; printf("Final score: %.3f\n", final_score); } else { int r = atoi(argv[1]); *(int*)MapViewOfFile(OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, (string("OhYeahMyDeskmateUniformAKedIOIButIGot100PointsInNOIP2025") + to_string(r)).c_str()), FILE_MAP_ALL_ACCESS, 0, 0, 0) = judge(T / dT); } return 0; }
|