Title Link: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142
Topic: Given a 0-9 numeric keypad, then enter an action sequence, that is, a key gesture, ask the sequence of actions on the keyboard to form a gesture is unique, yes, No. Gestures can be shifted up or down.
Problem Solving Ideas:
Because the number is very small, you can represent the position of the number of coordinates, according to the order of the gesture to match the other numbers (that is, the numbers are uniformly up or down or left or right translation), see the match after the number is not on the keyboard;
#include <cstdio>#include<iostream>using namespacestd;intn,coordinate[Ten][2]={2,1,1,4,2,4,3,4,1,3,2,3,3,3,1,2,2,2,3,2};intdir[4][2]={-1,0,1,0,0,-1,0,1};Charstr[Ten];intFindintd) { for(intI=0; i<n;i++) { intx=str[i]-'0'; if(x==0&& (d==0|| d==1|| d==2))return 0; if(coordinate[x][0]+dir[d][0]<1|| coordinate[x][0]+dir[d][0]>3|| (x!=8&&coordinate[x][1]+dir[d][1]<2)|| coordinate[x][1]+dir[d][1]>4) return 0; } return 1;}void out(){ intflag=0; for(intI=0;i<4; i++) if(Find (i)) {flag=1;if(flag) Break;} printf (Flag?"no\n":"yes\n");}intMain () { while(cin>>N) {scanf ("%s", str); out(); } return 0;}
View Code
Codeforces 689a-mike and Cellphone