[C++11]6个AC 4个WA,求助,谢
查看原帖
[C++11]6个AC 4个WA,求助,谢
475653
Hall_Code楼主2023/2/7 15:56

代码如下:

#include <iostream>
#include <climits>
#include <fstream>

using namespace std;

int _g, _l;
const int m_max = 500 + 2;
int box[m_max][m_max];
int bo_x, bo_y;
int check;

int main() {
	int _x, _y;
	cin >> bo_x >> bo_y >> _g >> _l;
	for (int i = 0; i < bo_x; i++) {
		for (int j = 0; j < bo_y; j++) {
			box[i][j] = 0;
		}
	}
	for (int i = 0; i < _g; i++){
		cin >> _x >> _y;
		box[(_x - 1)][(_y - 1)] = 1;
	}
	for (int k = 2;;) {
		check = 0;
		for (int i = 0; i < bo_x; i++) {
			for (int j = 0; j < bo_y; j++) {
				if ((i - 1) > 0 && (i - 1) < bo_x) { if (box[i][j] == 0 && box[i - 1][j] > 0) { box[i][j] = -1; check = 1; } }
				if ((i + 1) > 0 && (i + 1) < bo_x) { if (box[i][j] == 0 && box[i + 1][j] > 0) { box[i][j] = -1; check = 1; } }
				if ((j - 1) > 0 && (j - 1) < bo_y) { if (box[i][j] == 0 && box[i][j - 1] > 0) { box[i][j] = -1; check = 1; } }
				if ((j + 1) > 0 && (j + 1) < bo_y) { if (box[i][j] == 0 && box[i][j + 1] > 0) { box[i][j] = -1; check = 1; } }
			}
		}
		for (int i = 0; i < bo_x; i++) {
			for (int j = 0; j < bo_y; j++) {
				if (box[i][j] == -1)box[i][j] = k;
			}
		}
		k++;
		if (check == 0)break;
	}
	/*
	for (int j = 0; j < bo_y; j++) {
		for (int i = 0; i < bo_x; i++) {
			cout << box[i][j] << " ";
		}
		cout << "\n";
	}
	*/
	ofstream a_file;
	a_file.open("kk.txt");
	for (int i = 0; i < _l; i++) {
		cin >> _x >> _y;
		cout << (box[(_x - 1)][(_y - 1)] - 1) << "\n";
		a_file << (box[(_x - 1)][(_y - 1)] - 1) << "\n";
	}
	return 0;
}

fstream的函数请忽略,我用来测试的

WA的是3、6、9、10这几组 我下载第三组后发现十万个里面大约有十几个错了 有没有大佬看看为什么出这个问题 qwq

有问题欢迎讨论区提问,求大佬解答

2023/2/7 15:56
加载中...