为什么是50分求解答
查看原帖
为什么是50分求解答
775376
ZPL13366837721楼主2024/10/29 16:25

求大佬解答

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		int p,q,num,x,y,nw,t = 1;
		char a[1010][1010],used[1010][1010] = {0};
		cin >> p >> q >> num >> x >> y >> nw;
		for (int i = 1;i <= p;i++)
		{
			for (int j = 1;j <= q;j++)
			{
				cin >> a[i][j];
			}
		}
		a[x][y] = 1;
		while(num > 0)
		{
			if (nw == 0 && y + 1 <= q && a[x][y + 1] == '.')
			{
				y++;
				if (used[x][y] == 0)
				{
					t++;
					used[x][y] = 1;
				}
				num--;
			}
			else if (nw == 0)
			{
				nw++;
				num--;
			}
			else if (nw == 1 && x + 1 <= p && a[x + 1][y] == '.')
			{
				x++;
				if (used[x][y] == 0)
				{
					t++;
					used[x][y] = 1;
				}
				num--;
			}
			else if (nw == 1)
			{
				nw++;
				num--;
			}
			else if (nw == 2 && y - 1 >= 1 && a[x][y - 1] == '.')
			{
				y--;
				if (used[x][y] == 0)
				{
					t++;
					used[x][y] = 1;
				}
				num--;
			}
			else if (nw == 2)
			{
				nw++;
				num--;
			}
			else if (nw == 3 && x - 1 >= 1 && a[x - 1][y] == '.')
			{
				x--;
				if (used[x][y] == 0)
				{
					t++;
					used[x][y] = 1;
				}
				num--;
			}
			else if (nw == 3)
			{
				nw = 0;
				num--;
			}
		}
		if (used[x][y] == '.')
		{
			t++;
		}
		cout << t << endl;
	}
	return 0;
}
2024/10/29 16:25
加载中...