呕,大模拟太恶心了
改了三小时才找出来,接口有多位数,要用while抠数字出来
dfs暴搜加大模拟,恶心到不行,没什么好说的
#include <bits/stdc++.h>
using namespace std;
int n;
const int N=1e4+50;
queue<string> jincheng[N];
bool st[N];
typedef long long ll;
typedef pair<int,int> PII;
void read(){
for(int i=0;i<n;i++){
while(jincheng[i].size()) jincheng[i].pop();
string tmp;
getline(cin,tmp);
stringstream ssin(tmp);
while(ssin>>tmp) jincheng[i].push(tmp);
}
}
string get(int x){
string a="";
if(x==0) return "0";
while(x){
int t=x%10;
char c=t+'0';
a=c+a;
x/=10;
}
return a;
}
bool dfs(int u,string op){
if(st[u]) return false;
st[u]=true;
if(!jincheng[u].size()) return false;
if(op==jincheng[u].front()){
jincheng[u].pop();
st[u]=false;
return true;
}
while(jincheng[u].size()&&op!=jincheng[u].front()){
string tmp=jincheng[u].front();jincheng[u].pop();
string c=get(u);
string aa;
if(tmp[0]=='R') aa="S";
else aa="R";
aa+=c;
int id=0,idx=1;
while(idx<tmp.size()) id=id*10+(tmp[idx++]-'0');
if(!dfs(id,aa)) return false;
}
if(!jincheng[u].size()) return false;
if(jincheng[u].front()==op){
jincheng[u].pop();
st[u]=false;
return true;
}
return true;
}
void solve(){
read();
memset(st, 0, sizeof st);
bool flag=true;
for(int i=0;i<n;i++){
st[i]=true;
while(jincheng[i].size()){
string op=jincheng[i].front();jincheng[i].pop();
string aa;
string c=get(i);
int id=0,idx=1;
while(idx<op.size()) id=id*10+(op[idx++]-'0');
if(op[0]=='R') aa="S";
else aa="R";
aa=aa+c;
//aa也要改!!!,不止是1位数!!
if(!dfs(id,aa)){
flag=false;
break;
}
}
st[i]=false;
if(!flag) break;
}
puts(flag?"0":"1");
}
int main(){
int t;
scanf("%d%d",&t,&n);
getchar();
while(t--) solve();
return 0;
}
看了你的题解后发现我的错误原因是忽视接口多位数,多谢!