迷惑程序莫名RE求助/kel
查看原帖
迷惑程序莫名RE求助/kel
253765
houpingze楼主2021/4/22 22:43

rt,及其玄学,为啥re啊/kk

就是刚刚输入

143
3

就会re,及其玄学

/*houpingze stO CCF Orz*/ 
#include<bits/stdc++.h>
#define reg register int
#define INF (1<<30)
using namespace std;
int read(){
	int res=0,fs=1; char c=getchar();
	while(!(c>='0' && c<='9')){ if(c=='-')fs=-1; c=getchar(); }
	while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
	return res*fs;
}
void print(int x){
    if(x<0) { putchar('-'); x=-x;}
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int n,cnt,m,a[5010],tmp,k;
//string
map<string,int>ans;
string s;
struct Orz{
	string s;
	int x;
};
map<string,bool>vis;
void bfs(){
//	cout<<"??????\n";
	queue<Orz>q;
	q.push((Orz){
		s,0
	});
//	ans[s]=114514;
	vis[s]=1;
	while(!q.empty()){
//		if()
		Orz h=q.front();
		q.pop();  
		if(h.s.size()>s.size()) continue;
			ans[h.s]=h.x; 
//		if(ans[h.s]&&ans[h.s]!=114514) continue;
		for(int i=1;i<h.s.size();i++){
			cout<<1;
			swap(h.s[i],h.s[i-1]);
			if(!vis[h.s]){
				vis[h.s]=1;
				q.push((Orz){
					h.s,h.x+1
				});
			}
			swap(h.s[i],h.s[i-1]);
		}
		
//		string x=h.s,y="";
		for(int i=0;i<h.s.size();i++){
//			int c=s[]
//			s.erase(0,1);
			cout<<2;
			string x=h.s.substr(0,i),y=h.s.substr(i+1,h.s.size()-i-1);
			string c=x+y;
			
			if(!vis[c]){
				vis[c]=1;
				q.push((Orz){
					c,h.x+1
				});
			}
			
//			y=c+y;
		}
//		cout<<h.s<<endl;
//			cout<<h.s<<' '<<(char)(s[i]+1)<<' '<<char(s[i+1]-1)<<endl;
		for(int i=0;i<h.s.size()-1;i++){
//			cout<<3<<endl;
			string x=h.s.substr(0,i),y=h.s.substr(i,h.s.size()-i);
			
//			cout<<3<<endl;
//			cout<<3;
			for(char X=h.s[i]+1;X<h.s[i+1];X++){
//			cout<<3<<endl;
//				cout<<"Orz";
				string c=x+X+y;
//				cout<<"Orz";
//				cout<<h.s<<' '<<c<<endl;
				if(!vis[c]){
					vis[c]=1;
					q.push((Orz){
						c,h.x+1
					});
				}
			}
		}
	} 
}
int main() {
	ios::sync_with_stdio(false);
	cin>>s>>m; 
	bfs();
	while(m--){
		string t;
		cin>>t;
//		bfs(t);
		if(ans[t]==0&&!vis[t]) cout<<-1<<endl;
		else 
		cout<<ans[t]<<'\n';
	}	
    return 0;
}


2021/4/22 22:43
加载中...