1536B - Prinzessin der Verurteilung

BFS:

暴力枚举所有情况即可

#include <iostream>
#include <queue>
using namespace std;
int n;
string s;
string bfs () {
	queue <string> q;
	for (int i = 0;i < 26;i++) {
		string t;
		t += i+'a';
		q.push (t);
	}
	while (!q.empty ()) {
		string t = q.front ();
		q.pop ();
		if (s.find (t) == -1) return t;
		for (int i = 0;i < 26;i++) q.push (t+char(i+'a'));
	}
}
int main () {
	int T;
	cin >> T;
	while (T--) {
		cin >> n >> s;
		cout << bfs () << endl;
	}
	return 0;
}
posted @ 2022-06-19 09:45  incra  阅读(42)  评论(0)    收藏  举报