问题:
CSP 201903-4问题消息传递接口,得了0分,但是测试用例都通过了,不知道错哪儿了。
请求帮忙看一下哪里出了问题?
我的思路:
使用节点+队列模拟实现:
代码:
//
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
using namespace std;
int M,N;
struct Node {
int aim;
bool s; //1代表发送,0代表接收
};
void step() {
char in[60];
queue<Node> nodes[10001]; //每一个进程的代表
memset(in, 0, sizeof(in));
for(int n=0; n<N; n++) {
cin.sync();
fgets(in, 60, stdin); //前面需要加清空缓冲区的代码
char *subs=strtok(in, " \n");
while(subs){
Node nd;
if((subs[0])=='R'){
nd.s=0;
}else{
nd.s=1;
}
nd.aim=atoi(&subs[1]); // 使用&代表取了subs【1】的地址,相当于在此处填入字符串
nodes[n].push(nd);
subs=strtok(NULL, " \n");
}
}
//输出
// for(int i=0; i<N; i++) {
// cout<<i<<": ";
// for(int j=0;!nodes[i].empty();j++){
// Node nd=nodes[i].front();
// nodes[i].pop();
// cout<<nd.s<<" "<<nd.aim<<" ";
// }
// cout<<endl;
// }
// return ;
// 开始计算
int tag=1;
while(tag) {
tag=0;
for(int n=0; n<N; n++) {
if(nodes[n].empty()) continue;
Node nd=nodes[n].front();
if(nd.aim>=N||nodes[nd.aim].empty()){
printf("1\n");
return ;
}
Node nd2=nodes[nd.aim].front();
if(nd.s!=nd2.s) {
nodes[n].pop();
nodes[nd.aim].pop();
tag=1;
break;
}
}
}
for(int i=0;i<N;i++){
if(!nodes[i].empty()) {
printf("1\n");
return ;
}
}
printf("0\n");
return ;
}
int main() {
scanf("%d%d", &M,&N);
for(int m=0; m<M; m++) {
step();
}
return 0;
}
哪里错了???请大家帮忙看一下??