SK


私信TA

用户名:1973231998

访问量:18487

签 名:

成功只是一时的,失败才是主旋律,笑着面对失败是主要的。

等  级
排  名 261
经  验 5682
参赛次数 0
文章发表 59
年  龄 0
在职情况 学生
学  校 *
专  业

  自我简介:

解题思路:
暴力,照着题做就是,关键是只要路过终点,就可以直接结束当前步骤了。

然后代码看着长,好多都是复制粘贴的,但是也可以再优化。
参考代码:

#include<bits/stdc++.h>
using namespace std;
char mapp[51][51];
int main()
{
	int to;
	cin >> to;
	while (to--)
	{
		int n,s=0,t=0,s2=0,t2=0;
		cin >> n;
		for (int i = 0; i < n; i++)
		{
			scanf("%s",mapp[i]);
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (mapp[i][j] == 'S')
				{
					s = i;
					t = j;
				}
				else if (mapp[i][j] == 'T')
				{
					s2 = i;
					t2 = j;
				}
			}
		}
		int num;
		cin >> num;
		while (num--)
		{
			char ins[1001], * q;
			int s1 = s, t1 = t;
			scanf("%s",ins);
			q = ins;
			int count = 0;
			while (*q)
			{
				if (*q == 'L')
				{
					t1--;
					if (s1 == s2 && t1 == t2)
					{
						cout << "I get there!" << endl;
						count = 1;
						break;
					}
					if (t1<0 || t1>n - 1)
					{
						cout << "I am out!" << endl;
						count = 1;
						break;
					}
					if (mapp[s1][t1]=='#')
					{
						cout << "I am dizzy!" << endl;
						count = 1;
						break;
					}

				}
				else if (*q == 'R')
				{
					t1++;
					if (s1 == s2 && t1 == t2)
					{
						cout << "I get there!" << endl;
						count = 1;
						break;
					}
					if (t1<0 || t1>n - 1)
					{
						cout << "I am out!" << endl;
						count = 1;
						break;
					}
					if (mapp[s1][t1] == '#')
					{
						cout << "I am dizzy!" << endl;
						count = 1;
						break;
					}
				}
				else if (*q == 'U')
				{
					s1--;
					if (s1 == s2 && t1 == t2)
					{
						cout << "I get there!" << endl;
						count = 1;
						break;
					}
					if (s1<0 || s1>n - 1)
					{
						cout << "I am out!" << endl;
						count = 1;
						break;
					}
					if (mapp[s1][t1] == '#')
					{
						cout << "I am dizzy!" << endl;
						count = 1;
						break;
					}
				}
				else if (*q == 'D')
				{
					s1++;
					if (s1 == s2 && t1 == t2)
					{
						cout << "I get there!" << endl;
						count = 1;
						break;
					}
					if (s1<0 || s1>n - 1)
					{
						cout << "I am out!" << endl;
						count = 1;
						break;
					}
					if (mapp[s1][t1] == '#')
					{
						cout << "I am dizzy!" << endl;
						count = 1;
						break;
					}
				}
				q++;
			}
			if (count == 0)
			{
				if (s1 == s2 && t1 == t2) cout << "I get there!" << endl;
				else cout << "I have no idea!"<<endl;
			}
		}
	}

}


 

0.0分

4 人评分

  评论区