萌新22分求调
查看原帖
萌新22分求调
1396307
regina11楼主2024/9/4 12:43

本地编译运行没问题,但提交到洛谷之后发现WA了7个点,下载了#1到本地再次运行,与答案比对一致,但提交后显示的是我的程序输出为0

#include<iostream>
using namespace std;

const int N = 12, T = 10;
int chizu[N][N];
int mx, my, nx, ny, md = 1, nd = 1;

void move(int& d, int& x, int& y)
{
	if (d == 1)
	{
		if (chizu[x - 1][y] != 0)
			x--;
		else
			d = 2;
	}
	else if (d == 2)
	{
		if (chizu[x][y + 1] != 0)
			y++;
		else
			d = 3;
	}
	else if (d == 3)
	{
		if (chizu[x + 1][y] != 0)
			x++;
		else
			d = 4;
	}
	else
	{
		if (chizu[x][y - 1] != 0)
			y--;
		else
			d = 1;
	}
}

int main()
{
	int count = 0;
	for (int i = 1; i <= T; i++)
	{
		for (int j = 1; j <= T; j++)
		{
			char c = getchar();
			if (c == '.')
				chizu[i][j] = 1;
			else if (c == '*')
				chizu[i][j] = 0;
			else if (c == 'C')
			{
				chizu[i][j] = 1;
				mx = i, my = j;
			}
			else
			{
				chizu[i][j] = 1;
				nx = i, ny = j;
			}
		}
		char ch = getchar();//读掉换行
	}
	//cout << count << ":" << mx << " " << my << " " << md << " " << nx << " " << ny << " " << nd << endl;
	while (mx != nx || my != ny)
	{
		move(md, mx, my);
		move(nd, nx, ny);
		count++;
		//cout << count << ":" << mx << " " << my << " " << md << " " << nx << " " << ny << " " << nd << endl;
		if (count >= 1e3)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	cout << count << endl;
	return 0;
}
2024/9/4 12:43
加载中...