We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
先选一个与字符串其他字符串match为0个数最少的,然后猜这个数,选到与猜出的值相匹配的字符串集合,重新进行再猜
/** * // This is the Master's API interface. * // You should not implement it, or speculate about its implementation * class Master { * public: * int guess(string word); * }; */ class Solution { public: int match(string &s1, string &s2){ int r = 0; for(int i = 0; i < 6; i++){ if(s1[i] == s2[i]) r++; } return r; } void findSecretWord(vector<string>& ws, Master& master) { vector<int> w; for(int i = 0; i < ws.size(); i++) w.push_back(i); for(int i = 0; i < 10; i++){ unordered_map<int, int> m; for(int i = 0; i < w.size(); i++){ for(int j = 0; j < w.size(); j++){ if(match(ws[w[i]], ws[w[j]]) == 0) m[w[i]]++; } } int minCount = 1000; int minf = w[0]; for(int i = 0; i < w.size(); i++){ if(m[w[i]] < minCount){ minCount = m[w[i]]; minf = w[i]; } } int x = master.guess(ws[minf]); if(x == 6) return; vector<int> r; for(int i = 0; i < w.size(); i++){ if(match(ws[w[i]], ws[minf]) == x){ r.push_back(w[i]); } } w = r; } } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
先选一个与字符串其他字符串match为0个数最少的,然后猜这个数,选到与猜出的值相匹配的字符串集合,重新进行再猜
The text was updated successfully, but these errors were encountered: