A - Mike and Cellphone

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

Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES

题意:

 给出一个锁屏,问存不存在其他锁屏密码跟改密码有同样的移动模式(例如0->9和8->6 移动方向 距离都一样)

分析:

可以记录每个数字上下左右。然后枚举移动方向和距离,将整个号码拖着移动。看看合不合法。

也可以直接判断该锁屏是否都可以向相同的方向移动(是否都不存在在同一个边界上)如果可以则输出“NO”.

#include <iostream>
#include<cstdio>
using namespace std; int main()
{
int n,x=,y=,z=,l=;
char a[];
scanf("%d",&n);
cin>>a;
for(int i=;i<n;i++)
{
if(a[i]!=''&&a[i]!=''&&a[i]!='')
x++;
if(a[i]!=''&&a[i]!=''&&a[i]!='')
y++;
if(a[i]!=''&&a[i]!=''&&a[i]!=''&&a[i]!='')
z++;
if(a[i]!=''&&a[i]!=''&&a[i]!=''&&a[i]!='')
l++;
} if(x==n||y==n||z==n||l==n)
printf("%s\n","NO");
else
printf("%s\n","YES");
return ;
}

Codeforces Round #361 (Div. 2) A的更多相关文章

  1. Codeforces Round #361 (Div. 2) C.NP-Hard Problem

    题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. ...

  2. 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 ...

  3. Codeforces Round #361 (Div. 2) D. Friends and Subsequences 二分

    D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description Mike a ...

  4. Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...

  5. 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 ...

  6. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  7. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

  8. Codeforces Round #361 (Div. 2) D

    D - Friends and Subsequences Description Mike and !Mike are old childhood rivals, they are opposite ...

  9. Codeforces Round #361 (Div. 2) C

    C - Mike and Chocolate Thieves Description Bad news came to Mike's village, some thieves stole a bun ...

  10. Codeforces Round #361 (Div. 2) B

    B - Mike and Shortcuts Description Recently, Mike was very busy with studying for exams and contests ...

随机推荐

  1. The difference between QA, QC, and Test Engineering

    Tuesday, March 06, 2007 Posted by Allen Hutchison, Engineering Manager and Jay Han, Software Enginee ...

  2. IDEA tomcat乱码

    在运行/调试 配置对话框的Startup/Connection面板中, 勾选Pass environment variables. 并添加一个environment variable, Name填 J ...

  3. ssdb binlog机制 存疑

    int BinlogQueue::del_range(uint64_t start, uint64_t end){ while(start <= end){ leveldb::WriteBatc ...

  4. fabric

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # fab test   [root@192.168.85.99:22] Executing ...

  5. ATM

    package duzhaonan;import java.util.Scanner;import javax.swing.JOptionPane;class Account{//创建的账户类 Str ...

  6. 如何在Eclipse下查看JDK源代码

    在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 "window"-> "Preferences" -> "Java&quo ...

  7. hadoop2.6.4 搭建单机模式

    注(要先安装jdk,最好jdk版本>=1.7) 安装jdk  http://www.cnblogs.com/zhangXingSheng/p/6228432.html     给普通用户添加su ...

  8. php单点登录之模拟淘宝天猫同步登录

    说到单点登录大家都很了解,一个站点登录其他域会自动登录. 单点登录SSO(Single Sign On)的方法有很多,比如:p3p.共享session.共享cookice.第三方OAuth认证. 这里 ...

  9. 剑指Offer-【面试题05:从头到尾打印链表】

    package com.cxz.question5; import java.util.Stack; /* * 输入个链表的头结点,从尾到头反过来打印出每个结点的值. * */ public clas ...

  10. 搜索引擎广告过滤Chrome插件

    搜索广告屏蔽Chrome插件:自动过滤:百度,360,搜狗,google,bing的搜索广告,让魏则西的悲剧不再重演.珍爱生命,远离搜索广告! 下载:FuckAd.zip 安装:方法自行百度. 关闭百 ...