社区讨论

紧急求助, 悬1关

灌水区参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lo299mda
此快照首次捕获于
2023/10/23 10:05
2 年前
此快照最后确认于
2023/11/03 10:17
2 年前
查看原帖
这是一个鸭棋的半成品,问为什么编译器不报错却无法运行。
CPP
#include <bits/stdc++.h>
#define int long long
using namespace std;

void moveM(int i, char mode);
void moveX(int i, char mode);
void moveS(int i, char mode);
void moveW(int i, char mode);
void moveY(int i, char mode);
void moveB(int i, char mode);

int q, now;
bool game = 1;
char mp[11][10] = {
	"JMXSWSXMJ", ".........", "Y.......Y", "B.B.B.B.B", ".........",
	".........", ".........", "b.b.b.b.b", "y.......y", ".........", "jmxswsxmj"
};
struct XY {
	int x, y;
} fr[1010], to[1010];

string seewhat(char c) {
	switch(c) {
		case 'J': case 'j': return "car"; case 'M': case 'm': return "horse";
		case 'X': case 'x': return "elephant"; case 'S': case 's': return "guard";
		case 'W': case 'w': return "captain"; case 'Y': case 'y': return "duck";
		case 'B': case 'b': return "soldier";
	}
	return "";
}
bool checkd(int x, int y) {
	if(seewhat(mp[x][y]) == "car") {
		for(int i = x-1; i >= 0; i--) {
			if(mp[i][y] == '.') continue;
			if(seewhat(mp[i][y]) == "captain") return 1;
			break;
		}
		for(int i = x+1; i <= 9; i++) {
			if(mp[i][y] == '.') continue;
			if(seewhat(mp[i][y]) == "captain") return 1;
			break;
		}
		for(int i = y-1; i >= 0; i--) {
			if(mp[x][i] == '.') continue;
			if(seewhat(mp[x][i]) == "captain") return 1;
			break;
		}
		for(int i = y+1; i <= 8; i++) {
			if(mp[x][i] == '.') continue;
			if(seewhat(mp[x][i]) == "captain") return 1;
			break;
		}
	}
	return 0;
}
bool danger() {
	for(int i = 0; i <= 10; i++) {
		for(int j = 0; j <= 9; j++) {
			if(mp[i][j] != '.' && checkd(i, j)) return 1;
		}
	}
	return 0;
}
void moveJ(int i, char mode) {
	if(!game) {
		printf("Invalid command\n");
		return;
	}
	if(fr[i].x == to[i].x) {
		int a = fr[i].y, b = to[i].y;
		if(a > b) swap(a, b);
		for(int j = a+1; j < b; j++)
			if(mp[j][fr[i].x] != '.') {
				printf("Invalid command\n");
				return;
			}
		if(mode == 'r') {
			if(mp[to[i].x][to[i].y] <= 'Z' && mp[to[i].x][to[i].y] >= 'A') {
				printf("Invalid command\n");
				return;
			}
			else {
				printf("red car;");
				if(mp[to[i].x][to[i].y] == '.') printf("NA;");
				else cout << "blue " << seewhat(mp[to[i].x][to[i].y]) << ';';
				if(seewhat(mp[to[i].x][to[i].y]) == "captain") game = 0;
			}
		}
		else {
			if(mp[to[i].x][to[i].y] <= 'z' && mp[to[i].x][to[i].y] >= 'a') {
				printf("Invalid command\n");
				return;
			}
			else {
				printf("blue car;");
				if(mp[to[i].x][to[i].y] == '.') printf("NA;");
				else cout << "red " << seewhat(mp[to[i].x][to[i].y]) << ';';
				if(seewhat(mp[to[i].x][to[i].y]) == "captain") game = 0;
			}
		}
		mp[to[i].x][to[i].y] = mp[fr[i].x][fr[i].y];
		mp[fr[i].x][fr[i].y] = '.';
		if(!danger()) printf("no;");
		else printf("yes;");
		if(game) printf("no\n");
		else printf("yes\n");
	}
}
void redmove(int i) {
	if(mp[fr[i].x][fr[i].y] == 'J') moveJ(i, 'r');
	else if(mp[fr[i].x][fr[i].y] == 'M') moveM(i, 'r');
	else if(mp[fr[i].x][fr[i].y] == 'X') moveX(i, 'r');
	else if(mp[fr[i].x][fr[i].y] == 'S') moveS(i, 'r');
	else if(mp[fr[i].x][fr[i].y] == 'W') moveW(i, 'r');
	else if(mp[fr[i].x][fr[i].y] == 'Y') moveY(i, 'r');
	else if(mp[fr[i].x][fr[i].y] == 'B') moveB(i, 'r');
	else printf("Invalid command\n");
}
void bluemove(int i) {
	if(mp[fr[i].x][fr[i].y] == 'j') moveJ(i, 'b');
	else if(mp[fr[i].x][fr[i].y] == 'm') moveM(i, 'b');
	else if(mp[fr[i].x][fr[i].y] == 'x') moveX(i, 'b');
	else if(mp[fr[i].x][fr[i].y] == 's') moveS(i, 'b');
	else if(mp[fr[i].x][fr[i].y] == 'w') moveW(i, 'b');
	else if(mp[fr[i].x][fr[i].y] == 'y') moveY(i, 'b');
	else if(mp[fr[i].x][fr[i].y] == 'b') moveB(i, 'b');
	else printf("Invalid command\n");
}

signed main() {
	scanf("%lld", &q);
	for(int i = 1; i <= q; i++)
		scanf("%lld%lld%lld%lld", &fr[i].x, &fr[i].y, &to[i].x, &to[i].y);
	for(int i = 1; i <= q; i++) {
		if(!now) redmove(i);
		else bluemove(i);
	}
	
    return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...