A. Mike and Cellphone

题目连接:

http://www.codeforces.com/contest/689/problem/A

Description

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

3

586

Sample Output

NO

Hint

题意

有一个人把所有人的手机号码都忘了

但是他记得手指的动作,问你他手指的动作是不是唯一的一个号码

题解

暴力模拟一下去按键就好了……

代码

#include<bits/stdc++.h>
using namespace std; int n;
string s;
int x[10]={4,1,1,1,2,2,2,3,3,3};
int y[10]={2,1,2,3,1,2,3,1,2,3};
int mp[10][10];
bool check(int x3,int y3){
for(int i=0;i<s.size();i++)
{
int xx=max(x[s[i]-'0']-x3,0);
int yy=max(y[s[i]-'0']-y3,0);
if(mp[xx][yy]==0)return false;
}
return true;
}
int main(){
scanf("%d",&n);
cin>>s;
int ans = 0;
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)
mp[i][j]=1;
mp[4][2]=1;
for(int j=-4;j<=4;j++)
for(int k=-4;k<=4;k++)
if(check(j,k))
ans++;
if(ans>1)printf("No\n");
else printf("Yes\n");
}

Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题的更多相关文章

  1. Codeforces Round #361 (Div. 2)A. Mike and Cellphone

    A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  3. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  4. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  6. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  7. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  8. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  9. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合

    E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...

随机推荐

  1. Docker技术这些应用场景【转】

    场景一:节省项目环境部署时间 1.单项目打包 每次部署项目到测试.生产等环境,都要部署一大堆依赖的软件.工具,而且部署期间出现问题几率很大,不经意就花费了很长时间. Docker主要理念就是环境打包部 ...

  2. ArcMap2SLD使用

    1.首先打开ArcMap,加载一副mxd地图: 2.打开ArcGIS2SLD,如下图所示: 3.选择样式文件的保存形式,一副mxd地图可能有多个图层,选中In Separate Dateien/In ...

  3. 一步步教你编写不可维护的 PHP 代码

    译者注:这是一篇很棒文章,使用有趣的叙述方式,从反面讲解了作为一个优秀的 PHP 工程师,有哪些事情是你不能做的.请注意哦,此篇文章罗列的行为,都是你要尽量避免的. 随着失业率越来越高,很多人意识到保 ...

  4. JAVA 解析TXT文本

    package file; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im ...

  5. 企业级Docker Registry —— Harbor搭建和使用

    本节内容: Harbor介绍 安装部署Harbor 环境要求 环境信息 安装部署harbor 配置harbor 配置存储 完成安装和启动harbor 访问Harbor 修改管理员密码 启动后相关容器 ...

  6. Ionic入门六:按钮

    1.基本使用 按钮是移动app不可或缺的一部分,不同风格的app,需要的不同按钮的样式. 默认情况下,按钮显示样式为:display: inline-block. <button class=& ...

  7. 关于ecshop的mobile里user.php登录和注册验证码不显示

    在做ecshop模板的时候由于user.php里的登录和注册是在一个页面里切换的,这就致使这里的登录和注册里的验证码不显示 找到mobile/themesmobile/ecshoptemplate_m ...

  8. js判断一个字符串是否是数字

    function isNumber(val) { var regPos = /^\d+(\.\d+)?$/; //非负浮点数 var regNeg = /^(-(([0-9]+\.[0-9]*[1-9 ...

  9. RTSP 资料

    分享两个不错的播客. http://blog.csdn.net/u010425035/article/details/10410851 http://blog.csdn.net/xiaoyafang1 ...

  10. 洛谷P2597 [ZJOI2012] 灾难 [拓扑排序,LCA]

    题目传送门 灾难 题目描述 阿米巴是小强的好朋友. 阿米巴和小强在草原上捉蚂蚱.小强突然想,如果蚂蚱被他们捉灭绝了,那么吃蚂蚱的小鸟就会饿死,而捕食小鸟的猛禽也会跟着灭绝,从而引发一系列的生态灾难. ...