A. Mike and Cellphone
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
3
586
output
NO
input
2
09
output
NO
input
9
123456789
output
YES
input
3
911
output
YES
Note

You can find the picture clarifying the first sample case in the statement above.

直接暴力模拟。

记录一下状态,然后暴力枚举每一个位置,看看有几个位置满足那个状态,如果答案数大于1  那么他就有可能播错电话。..

ccf上有一个类似的..我是不是在做广告...

/* ***********************************************
Author :guanjun
Created Time :2016/7/7 22:40:13
File Name :cf361.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;int a[maxn];
int b[][]={
,,,
,,,
,,,
INF,,INF
};
map<int,pair<int,int> >mp;
int main()
{
int n;
string s;
cin>>n;
cin>>s;
for(int i=;i<n;i++){
a[i+]=s[i]-'';
}
for(int i=;i<;i++){
for(int j=;j<;j++){
mp[b[i][j]]={i,j};
}
}
vector<pair<int,int> >v;
int t=;
for(int i=;i<=n;i++){
int x=mp[a[i]].first-mp[a[t]].first;
int y=mp[a[i]].second-mp[a[t]].second;
v.push_back({x,y});
t=i;
}
int ans=;
int m=v.size();for(int i=;i<;i++){
for(int j=;j<;j++){
if(b[i][j]==INF)continue;
int k;
int ox=i;
int oy=j;
for(k=;k<m;k++){
int x=ox+v[k].first;
int y=oy+v[k].second;
if(x>=||y>=||x<||y<)break;
if(b[x][y]==INF)break;
ox=x;
oy=y;
}
if(k==m)ans++; }
}
if(ans>)puts("NO");
else puts("YES");
return ;
}

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

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

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

  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) C. Mike and Chocolate Thieves 二分

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

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

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

  6. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元

    E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input ...

  7. Codeforces Round #361 (Div. 2)——B. Mike and Shortcuts(BFS+小坑)

    B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem

    题目链接:传送门 题目大意:给你n个区间,求任意k个区间交所包含点的数目之和. 题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt ...

  9. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

随机推荐

  1. Saving James Bond - Hard Version

    07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...

  2. Java学习之跳转语句

    Java语言中提供3中跳转语句,分别是break语句.continue语句和return语句. break语句 可以用在switch语句中.在switch语句中,break语句用于中止下面的case语 ...

  3. BZOJ 1022: [SHOI2008]小约翰的游戏John【anti-SG】

    Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取 ...

  4. POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】

    题目链接: http://poj.org/problem?id=2109 参考: http://blog.csdn.net/code_pang/article/details/8263971 题意: ...

  5. Codeforces 653B Bear and Compressing【DFS】

    题目链接: http://codeforces.com/problemset/problem/653/B 题意: 要求你构造一个长度为n的字符串使得通过使用m个操作,最终获得字符a.已知第i个操作将字 ...

  6. BZOJ——T 1707: [Usaco2007 Nov]tanning分配防晒霜

    http://www.lydsy.com/JudgeOnline/problem.php?id=1707 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 8 ...

  7. mongodb按照日期分组统计

    目录 1.使用时间格式化方法 2.进行时间补偿(默认当前时区是东八区,即8x3600x1000=28800000) mongodb的默认时间是格林尼治时间,如果是要按照日期进行分组需要注意!!!. 解 ...

  8. dnsmasq possible DNS-rebind attack detected错误

    最近在做openwrt的平台,dns使用的是dnsmasq,但是通过板子上网,将PC的dns设置成板子的时候,发现百度等都可以,但是公司邮箱打不开.公司邮箱的域名 xx-xx-notes.xxx.co ...

  9. POJ 1436 Horizontally Visible Segments(线段树)

    POJ 1436 Horizontally Visible Segments 题目链接 线段树处理染色问题,把线段排序.从左往右扫描处理出每一个线段能看到的右边的线段,然后利用bitset维护枚举两个 ...

  10. windows下 sqlplus / as sysdba 报ora-12560的终极解决方法

    windows下 sqlplus / as sysdba 报ora-12560的终极解决方法 本文是原创文章.转载请注明出处:http://blog.csdn.net/msdnchina/articl ...