Test instructions: Given a phone keypad number nine Gongge, and then let you determine whether a certain operation is not unique, that is, it can be achieved by panning.
Analysis: My idea is that pan, see can be achieved, on the four translation, on, down, left, right, on IS-3, to note that 0 becomes 8, if there is a number less than or equal to 0, then is not, the same, the next +3,8 can become 0, the other is the same,
Note that the left and right panning is 147, and 369, is not translational and then on AC. Again simplified is if there is 123, you can not move up, if there is 79 can not move, if there is 147 can not move to the left, if there is 369 can not move right, if there is 0 can not move around.
The code is as follows:
#include <iostream> #include <cstdio>using namespace Std;const int maxn = 9 + 5;int a[maxn];int B[maxn];char s[ Maxn];int Main () {int n; while (scanf ("%d", &n) = = 1 && N) {scanf ("%s", s); for (int i = 0; i < n; ++i) a[i] = s[i]-' 0 '; bool OK = false; for (int i = 0; i < n; ++i)//Lower if (A[i] && a[i]! = 8) B[i] = A[i] + 3; else if (a[i] = = 8) B[i] = 0; else b[i] = 10; int i; for (i = 0; i < n; ++i) if (B[i] > 9) break; if (i = = N) ok = true; for (i = 0; i < n; ++i)//Upper if (A[i]) b[i] = A[i]-3; else b[i] = 8; for (i = 0; i < n; ++i) if (B[i] <= 0) break; if (i = = N) ok = true; for (i = 0; i < n; ++i)//Right if (3 = = A[i] | | 6 = a[i] | | 9 = a[i]) b[i] = 10; else if (A[i]) b[i] = A[i] + 1; else b[i] = 10; for (i = 0; i < n; ++i) if (B[i] > 9) break; if (i= = N) ok = true; for (i = 0; i < n; ++i)//left if (a[i] = = 1 | | a[i] = = 4 | | a[i] = = 7) B[i] = 10; else if (A[i]) b[i] = a[i]-1; else B[i] =-10; for (i = 0; i < n; ++i) if (B[i] <= 0) break; if (i = = N) ok = true; if (!ok) puts ("YES"); Else puts ("NO"); } return 0;}
The second type:
#include <iostream> #include <cstdio>using namespace Std;const int maxn = 9 + 5;int a[maxn];int B[maxn];char s[ Maxn];int Main () { int n; while (scanf ("%d", &n) = = 1 && N) { scanf ("%s", s); int l = 0, u = 0, r = 0, d = 0; for (int i = 0; i < n; ++i) { if (s[i] = = ' 0 ') L = r = d = 1; if (s[i] = = ' 1 ' | | s[i] = = ' 4 ' | | s[i] = = ' 7 ') L = 1; if (s[i] = = ' 3 ' | | s[i] = = ' 6 ' | | s[i] = = ' 9 ') r = 1; if (s[i] = = ' 1 ' | | s[i] = = ' 2 ' | | s[i] = = ' 3 ') u = 1; if (s[i] = = ' 7 ' | | s[i] = = ' 9 ') d = 1; } if (U && d && L && R) puts ("YES"); Else puts ("NO"); } return 0;}
Coderforces 689A Mike and Cellphone (water problem)