链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121473#problem/A

Mike and Cellphone

                               Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:

Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":

Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?

Input

The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.

The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.

Output

If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.

Otherwise print "NO" (without quotes) in the first line.

Sample Input

Input
3586

Output
NO

Input
209

Output
NO

Input
9123456789

Output
YES

Input
3911

Output
YES

题意:如果手指行走路线只有一条,就可以确定数值,输出YES,否者输出NO。解析:有两种方法1、计算两点之间的差额,从头开始,直接寻找。源代码:
 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 struct node{
 5     int x,y;
 6 }a[9];
 7 int main()
 8 {
 9     node a[]={3,1,0,0,0,1,0,2,1,0,1,1,1,2,2,0,2,1,2,2};//每个数所在的位置
10     int d[4][3]={1,2,3,4,5,6,7,8,9,-1,0,-1};//每个位置上的数
11     int n;
12     int b[10][2];
13     char c[10];
14     scanf("%d",&n);
15     int k=0;
16     scanf("%s",c);
17     for(int i=1;i<n;i++)
18     {
19         b[k][0]=a[c[i]-'0'].x-a[c[i-1]-'0'].x;   //更改的x值
20         b[k][1]=a[c[i]-'0'].y-a[c[i-1]-'0'].y;    //更改的y值
21         k++;
22     }
23     int i,j,t=0;
24     for(i=0;i<=9;i++)
25     {
26         int s=i;
27         for(j=0;j<k;j++)
28         {
29             int xx=a[s].x+b[j][0];
30             int yy=a[s].y+b[j][1];
31             if(xx>=0&&xx<4&&yy>=0&&yy<3&&d[xx][yy]>=0)    //确定是否可以移动
32                  s=d[xx][yy];   //更改第一个点
33             else
34                 break;
35         }
36         if(j>=k)   //有相同路径
37                 t++;
38     }
39     if(t>1)
40         printf("NO\n");
41     else
42         printf("YES\n");
43     return 0;
44 }

2、设上下左右方向的向量分别为U、D、L、R,当不可向该方向移动时对应的字母值为1。例如当操作序列含0时,左右下都不可移动,则L=R=D=0;

当所有方向都不可走时,即手势唯一

源代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main(){
 5     int n;
 6     char s[10000];
 7     while(cin>>n>>s)
 8     {
 9         int U=0,D=0,L=0,R=0;
10         for(int i=0;i<n;i++)
11         {
12             if(s[i]=='0')
13                 D=R=L=1;
14             if(s[i]=='1'||s[i]=='2'||s[i]=='3')
15                 U=1;//上
16             if(s[i]=='1'||s[i]=='4'||s[i]=='7')
17                 L=1;//左
18             if(s[i]=='3'||s[i]=='6'||s[i]=='9')
19                 R=1;//右
20             if(s[i]=='7'||s[i]=='9')
21                 D=1;//下
22         }
23         if(U==1&&D==1&&R==1&&L==1)
24             cout<<"YES"<<endl;
25         else
26             cout<<"NO"<<endl;
27     }
28     return 0;
29 }

转载于:https://www.cnblogs.com/q-c-y/p/5660107.html

Mike and Cellphone相关推荐

  1. 2016区域赛前冲刺训练

    UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...

  2. css设置height无效,CSS中设置height:100%无效的解决方案

    li 前面的缩进怎么去除? 异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 设置margin和padding为0或者为比较小的值就 ...

  3. (CodeForces 548B 暴力) Mike and Fun

    http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...

  4. 比特币前核心开发者Mike Hearn三年前的预测一一应验

    "多年以后,奥雷连诺上校站在行刑队面前,准会想起父亲带他去参观冰块的那个遥远的下午." 时间过的很快,对于暴涨暴跌的比特币来说更是如此,从最初的一文不值到一万八千美元一枚,比特币仅 ...

  5. D - Mike and strings

    D - Mike and strings Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters ...

  6. Codeforces Round #361 (Div. 2) B. Mike and Shortcuts bfs

    B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mi ...

  7. Codeforces 798C:Mike and gcd problem

    Codeforces 798C:Mike and gcd problem 题目链接:http://codeforces.com/contest/798/problem/C 题目大意:给出一个大小为$n ...

  8. 敏捷宣言和企业Scrum作者Mike Beedle去世

    \ 看新闻很累?看技术新闻更累?试试下载InfoQ手机客户端,每天上下班路上听新闻,有趣还有料! \ \\ 敏捷软件开发宣言发起者之一.企业Scrum开发方法论发明者Mike Beedle去世,留下了 ...

  9. CodeForces 689B Mike and Shortcuts (bfs or 最短路)

    Mike and Shortcuts 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/F Description Recently ...

  10. G - Mike and gcd problem

    G - Mike and gcd problem Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the seq ...

最新文章

  1. IDEA2021全局配置maven
  2. 豪斯荷尔德变换及变形QR算法对矩阵进行奇异值分解VB算法
  3. select元素的各种jquery修改获取添加方法
  4. 【ajax+php】动态展示4级单位(省、市、县、镇)
  5. 标题在图表上_从零开始学Excel——标题和图例的设置(143)
  6. jQuery用面向对象的思想来编写验证表单的插件
  7. PHP小语种网站开发,当阳小语种建站
  8. HDOJ 2037:今年暑假不AC_大二写
  9. JetBrains下载历史版本
  10. 真香!8 行代码搞定最大子数组和问题
  11. 【计算机就业-银行】校招想去银行该怎么准备
  12. Linux线程的同步,linux线程同步
  13. 树莓派如何连接WiFi
  14. MAC 网速问题 变慢 的来看看 经验
  15. 未了(endless)([CCF] NOI Online 能力测试2 入门组第一题)
  16. 阿里无人超市 “微笑打折”成世界互联网大会热点
  17. libhv教程11--创建一个简单的HTTP客户端
  18. 实用创意马赛克效果短视频转场过渡pr模板
  19. 【转】电路板绘制经验积累 (一至五)
  20. 清理autodesk产品注册表_如何完整移除Autodesk的产品?

热门文章

  1. 计算机考研408考试科目及备考指南
  2. 计步 android 源码,android版简易计步器源码
  3. visio业务流程图教学_用visio软件怎样画数据流程图和业务流程图?
  4. html怎么打开一个新窗口打开文件,js怎么打开新窗口
  5. 搭建samba映射网络驱动器
  6. 【在线分享】考研数学思维导图+高数思维导图+汤家凤重点笔记+武忠祥重点笔记以及高数Xmind思维导图
  7. 微信应用开发简单示例,学生自助报道系统
  8. 我的Android进阶之旅------经典的大牛博客推荐(排名不分先后)!!
  9. CUDA C编程(二)CUDA编程模型
  10. 在Linux和qt下安装EasyPr遇到的问题