【玄关】神秘RE求条
查看原帖
【玄关】神秘RE求条
556072
wang1h楼主2024/9/23 23:14

P1225 黑白棋游戏

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
const int n=4,m=n*n,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
struct node{string now,stp;}u,v;
string st,ed,tmp;
queue<node>q;
map<string,bool>mp;
void f(int &x,int &y,int z){y=z%n;x=(z-y)/n;}
void g(int x,int y,int &z){z=x*n+y;}
string h(int x){
	if(x==0)return"0";
	if(x==1)return"1";
	if(x==2)return"2";
	if(x==3)return"3";
	return"4";
}
void pr(string &s){
	int len=s.size();
	printf("%d",len/4);
	for(int i=0;i<len;i++){
		if(!(i%4))putchar('\n');
		putchar(s[i]+1);
	}
}
void bfs(){
	q.push({st,""});
	mp[st]=1;
	while(!q.empty()){
		u=q.front();q.pop();
//		cout<<u.now<<" ### "<<u.stp<<endl;
		if(u.now==ed){pr(u.stp);return;}
		for(int z=0,x,y,xx,yy,zz;z<m;z++)
			if(u.now[z]=='1'){
				f(x,y,z);
				for(int i=0;i<4;i++){
					v=u;xx=x+dx[i];yy=y+dy[i];
					g(xx,yy,zz);
					swap(v.now[z],v.now[zz]);
					if(xx<0||yy<0||xx>=n||yy>=n||mp[v.now])continue;
					v.stp+=h(x)+h(y)+h(xx)+h(yy);
					mp[v.now]=1;
					q.push(v);
				}
			}
	}
}
int main(){
	for(int i=0;i<n;i++)cin>>tmp,st+=tmp;
	for(int i=0;i<n;i++)cin>>tmp,ed+=tmp;
	bfs();
	cout<<"RE1";
	return 0;
	cout<<"RE2";
}

样例正常输出,并且额外输出RE1

RE信息:Runtime Error. Received signal 6: Aborted / IOT trap.


真的太神秘了,在return 0;的上一行能正常输出,但RE???

2024/9/23 23:14
加载中...