提供 SPJ
查看原帖
提供 SPJ
555825
block_in_mc楼主2024/9/13 15:11
#include "testlib.h"

int main(int argc, char* argv[]) {
	registerTestlibCmd(argc, argv);
	
	// 读入输入数据 
	int value[20][20];
	int n = inf.readInt(), m = inf.readInt(), k = inf.readInt();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			value[i][j] = inf.readInt();
	
	// 判断答案是否正确 
	std::string res = ouf.readLine(), correct = ans.readLine();
	while (!res.empty() && res.back() == ' ') res.pop_back();
	while (!correct.empty() && correct.back() == ' ') correct.pop_back();
	if (res != correct) quitf(_wa, "Your answer is wrong.");
	
	// 获得正确答案
	correct.erase(0, 6);
	int cans = stoi(correct);
	
	// 判断答案与方案是否对应,且数量为 K 个 
	int mk[20][20];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			mk[i][j] = 0;
	int sum = 0;
	for (int i = 1; i <= k; i++) {
		int x = ouf.readInt(), y = ouf.readInt();
		if (x < 1 || x > n || y < 1 || y > m) quitf(_wa, "Your plan chooses a block that doesnt exist.");
		if (mk[x][y]) quitf(_wa, "Your plan chooses a block for more the one times.");
		sum += value[x][y];
		mk[x][y] = 1;
	}
	if (sum != cans) quitf(_wa, "Your plan is different from your answer.");
	
	// 判断图形是否是凸多边形 
	for (int i = 1; i <= n; i++) {
		int cnt = 0, l = m, r = 1;
		for (int j = 1; j <= m; j++)
			if (mk[i][j])
				cnt++, l = std::min(l, j), r = std::max(r, j);
		if (cnt == 0) continue;
		if (r - l + 1 != cnt) quitf(_wa, "Your plan is not available.");
	}
	for (int j = 1; j <= m; j++) {
		int cnt = 0, l = n, r = 1;
		for (int i = 1; i <= n; i++)
			if (mk[i][j])
				cnt++, l = std::min(l, i), r = std::max(r, i);
		if (cnt == 0) continue;
		if (r - l + 1 != cnt) quitf(_wa, "Your plan is not available.");
	}
	
	quitf(_ok, "Correct answer!");
	return 0;
}
2024/9/13 15:11
加载中...