Prinzessin der Verurteilung(bfs STL)

谴责公主 - CodeForces 1536B - 虚拟法官 (csgrandeur.cn)

(29条消息) codeforces 1536B. Prinzessin der Verurteilung(1200)_Theiar的博客-CSDN博客

题意:求字典序最小的且不是给定字符串中连续字符组成的子串的字符串

暴力求一个字符串的全部连续字符子串

set<string> st;
for(int i=0;i<s.size();i++)
	{
		for(int j=1;i+j<=s.size();j++)
		{
			string t=s.substr(i,j);
			st.insert(t);
		}
	}
​
#include<bits/stdc++.h>
#define x first
#define gcfx main
#define y second
#define mak make_pair
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(a) cout<<a<<'\n'
#define endl '\n'
#define umap unordered_map
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=2e5+10,M=1,inf=0x3f3f3f3f,mod=1e9+7;
int t,n;
queue<string> q;
string res,s;
set<string> st;
void bfs()
{
	string x;q.push(x);
	while(q.size())
	{
		string temp=q.front();q.pop();
		if(st.find(temp)==st.end()&&temp.size()!=0)
		{
			res=temp;
			return;
		}
		for(int i=0;i<26;i++)
		{
			string t=temp+char('a'+i);
			q.push(t);
		}
	}
}
void solve()
{
	cin>>n>>s;
	res.clear();
	st.clear();
	for(int i=0;i<s.size();i++)
	{
		for(int j=1;i+j<=s.size();j++)
		{
			string t=s.substr(i,j);
			st.insert(t);
		}
	}
	bfs();
	cout<<res<<endl;
	while(q.size()) q.pop();
}

int gcfx()
{
	IOS;
	cin>>t;
	while(t--) solve();
	return 0;
}


​

END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值