『agc 003a』wanna go back home Solution

传送门:

传送door♂

Solution

显然,我们可以得到以下结论:

  • 如果$S$和$N$一个出现而另一个没有出现,显然是不行的
  • 如果$E$和$W$一个出现而另一个没有出现,显然是不行的
  • 除了以上的两种情况,其他情况都可行

代码就很easy了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
bool S, E, N, W;
string s;
int ()
{
ios::sync_with_stdio(false);
cin.tie(0);

cin >> s;
for (register int i = 0; i < s.length(); i++)
{
if (s[i] == 'S') S = 1;
if (s[i] == 'E') E = 1;
if (s[i] == 'N') N = 1;
if (s[i] == 'W') W = 1;
}
if ((S ^ N) || (E ^ W)) puts ("No");
else puts ("Yes");
return 0;
}