Codeforces 689a-mike and Cellphone

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.