IDA*奇怪错误求调
  • 板块题目总版
  • 楼主Noivelist
  • 当前回复8
  • 已保存回复8
  • 发布时间2025/8/5 09:04
  • 上次更新2025/8/5 13:34:25
查看原帖
IDA*奇怪错误求调
700335
Noivelist楼主2025/8/5 09:04

:::align{center} P2324骑士精神 传送门
:::


:::align{center}

问题很奇怪

::: 我在本地跑的十个官方数据全都是对的(我老师拉下来的)
在自己的OJ上跑的全是WA
代码表现和26行替换为
if (a[i][j] != mod[i][j] && mod[i][j] != 0) 一致
而在luogu上则全是RE
百思不得其解,并且调了一个小时
遂发帖求助


CODE\LARGE C \large^O\Large _D\small E

并附一组数据于下

#include<iostream>
#include<cstdio>

using namespace std;

int dx[9] = {0,-2,-2, 2, 2, 1, 1,-1,-1};
int dy[9] = {0, 1,-1, 1,-1, 2,-2, 2,-2};
int T=0;
int a[6][6];
int q=0;
char c;
int mod[6][6] = {
				 {0,0,0,0,0,0},
			     {0,2,2,2,2,2},
			     {0,1,2,2,2,2},
			     {0,1,1,0,2,2},
			     {0,1,1,1,1,2},
			     {0,1,1,1,1,1}
				};


int calc(){
	int res=0;
	for (int i = 1; i <= 5; i++) {
		for (int j = 1; j <= 5; j++) {
			if (a[i][j] != mod[i][j]) {
				res++;
			}
		}
	}
	return res;
}
bool dfs(int x, int y, int dep) {
	if(!calc())
		return true;
	if(calc() + dep - 1 > q)
		return false;
	for (int i = 1; i <= 8 ; i++ ) {
		int xx = x + dx[i], yy = y + dy[i];
		if (xx < 1 || xx > 5 || yy < 1 || yy > 5)
			continue;
		swap (a[xx][yy], a[x][y]);
		if (dfs(xx, yy, dep+1))
			return true;
		swap (a[xx][yy], a[x][y]);
	}
}
int main(){
	cin >> T;
	while (T--) {
		q = 0;
		int Noivelist = 0, swx = 0;
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= 5; j++) {
				cin >> c;
				if (c == '0') a[i][j] = 1;
				if (c == '1') a[i][j] = 2;
				if (c == '*') a[i][j] = 0, Noivelist = i, swx = j;
		}}
		if ( !calc()) {
			cout << 0 << endl;
			continue;
		}
		while ( !dfs(Noivelist, swx, 0) && q <= 15) q++;
		if (q == 16) printf("-1\n");
		else printf("%d\n",q);
	}
	return 0;
}

INPUT:

10
1*011
01011
01111
00001
00001
11101
01111
00010
01101
000*0
11011
01111
00*01
01001
00100
11111
01011
10011
0*001
00000
10111
01111
10000
01101
00*00
11111
01011
00011
01001
000*0
11001
11101
01011
10*01
00000
10111
1111*
10010
00001
00010
11011
0*010
10011
01011
00100
1*011
01110
11000
01001
10100

OUTPUT:

11
9
8
4
12
5
9
9
14
-1
2025/8/5 09:04
加载中...