为什么测试点1的答案是对的过不了?
查看原帖
为什么测试点1的答案是对的过不了?
477635
pppqqc楼主2021/1/28 18:59
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <sstream>
using namespace std;

char G[10][10];
int fvisit[10][10][4] = { 0 };
int cvisit[10][10][4] = { 0 };
int fx, fy, cx, cy;
int X[4] = { -1,0,1,0 }, Y[4] = { 0,1,0,-1 };
int main() {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			scanf("%c", &G[i][j]);
			if (G[i][j] == 'F') {
				fx = i; fy = j;
			}
			if (G[i][j] == 'C') {
				cx = i; cy = j;
			}
		}
		getchar();
	}
	G[fx][fy] = G[cx][cy] = '.';
	int fdir = 0, cdir = 0;
	int time = 0;
	while (!(fx == cx && fy == cy)) {
		if (fvisit[fx][fy][fdir] == 1 && cvisit[cx][cy][cdir] == 1) {
			printf("0");
			return 0;
		}
		fvisit[fx][fy][fdir] = 1;
		cvisit[cx][cy][cdir] = 1;
		int dfx = fx + X[fdir];
		int dfy = fy + Y[fdir];
		int dcx = cx + X[cdir];
		int dcy = cy + Y[cdir];
		if (dfx < 0 || dfx > 9 || dfy < 0 || dfy > 9 || G[dfx][dfy] == '*') {
			fdir = (fdir + 1) % 4;
		}
		else {
			fx = dfx; fy = dfy;
		}
		if (dcx < 0 || dcx > 9 || dcy < 0 || dcy > 9 || G[dcx][dcy] == '*') {
			cdir = (cdir + 1) % 4;
		}
		else {
			cx = dcx; cy = dcy;
		}
		time++;
	}
	printf("%d", time);
}

实在找不出哪里有问题了,测试点1的答案是对的但是过不了

2021/1/28 18:59
加载中...