关于文件输入
  • 板块学术版
  • 楼主TLE_Forever
  • 当前回复8
  • 已保存回复8
  • 发布时间2021/7/22 10:58
  • 上次更新2023/11/4 13:52:09
查看原帖
关于文件输入
286238
TLE_Forever楼主2021/7/22 10:58

终端手动输入没有问题

freopen("maze.in","r",stdin); 的注释删掉就不能正常运行了

用了 Dev 和 CB 都没有用

编译选项 g++ ... -std=c++98

运行结束的信息:

--------------------------------
Process exited after 7.656 seconds with return value 3221225477
请按任意键继续. . .

代码(一个宽搜程序):

#include<cstdio>
#include<queue>

struct node {
	int x;
	int y;
	int bomb;
	int step;
};
std::queue<node> q;
#define MAXN 51
int n,m,sx,sy,k,ans=0x7fffffff;
int dx[5]={0,2,-2,0,0};
int dy[5]={0,0,0,2,-2};
bool vis[2*MAXN+1][2*MAXN+1][16],Map[2*MAXN+1][2*MAXN+1];
char ch;

int main() {
	freopen("maze.in","r",stdin);
	freopen("maze.out","w",stdout);

	scanf("%d%d%d%d%d",&n,&m,&sx,&sy,&k);
	ch=getchar();
	for(int i=1;i<=2*n+1;i++) {
		int j=0;
		while((ch=getchar())!='\n') Map[i][++j]=(ch!=' ');
	}

/*	for(int i=1;i<=2*n+1;i++) {
		for(int j=1;j<=2*m+1;j++) putchar(Map[i][j]+'0');
		puts("");
	}*/

	q.push((node){sx*2,sy*2,0,1});
	while(!q.empty()) {
		node cur=q.front(),next;
		q.pop();
		vis[cur.x][cur.y][cur.bomb]=true;

		printf("x:%d y:%d bomb:%d step:%d\n",cur.x,cur.y,cur.bomb,cur.step);

		if(cur.x==2*n&&cur.y==2*m) {ans=cur.step; break;}

		for(int i=1;i<=4;i++) {
			next.x=cur.x+dx[i]; next.y=cur.y+dy[i];
			if(Map[cur.x+dx[i]/2][cur.y+dy[i]/2]&&cur.bomb==k) continue;
			else next.bomb=cur.bomb+Map[cur.x+dx[i]/2][cur.y+dy[i]/2];

			if(next.x>=1&&next.x<=2*n+1&&next.y>=1&&next.y<=2*m+1&&!vis[next.x][next.y][next.bomb]) {
				next.step=cur.step+1;
				q.push(next);
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}
2021/7/22 10:58
加载中...