B. Prinzessin der Verurteilung
此题主要解题关键点就是Pigeonhole principle。
确实是没往数据方面思考直接纯模拟做的,非常蠢。可以看出最多三位字符串按字典就已经有26 + 26 * 26 + 26 * 26 * 26 > 1000了,所以MEX的最大长度就是3。那就可以预处理一下就好了,但是自己在处理的时候非常蠢,我才发现to_string依然会把char变为int存进去,于是看了neal的代码。。。思路其实挺清晰了就是没实现出来,string的这些stl总是背不下来,这次记住.find()函速的使用以及vector<string>的初始化还有.swap()函数的使用。
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 #define gogo ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 5 6 const string YES = "YES"; 7 const string NO = "NO"; 8 9 string MEX(string s) { 10 vector<string> lop = {""}; 11 12 while (1) { 13 vector<string> com; 14 15 for (auto str : lop) 16 for (int i = 0;i < 26;i ++) { 17 string mn = str + char(i + 'a'); 18 com.push_back(mn); 19 if (s.find(mn) == string::npos) 20 return mn; 21 } 22 lop.swap(com); 23 } 24 } 25 26 void run() { 27 int n; 28 string s; 29 cin >> n >> s; 30 cout << MEX(s) << '\n'; 31 } 32 33 int32_t main() { 34 gogo; 35 36 int tt; 37 cin >> tt; 38 while (tt --) 39 run(); 40 41 return 0; 42 }

浙公网安备 33010602011771号