您的位置:首页 > 其它

Codeforces Round #361 (Div. 2) A

2016-07-10 09:23 239 查看
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.

题意:判断一组手势的顺序(0~9数字可以重复)长度最多为9是否是唯一的 如果唯一则输出YES 否则NO

题解:首先判断给出的手势顺序的坐在区域上下左右界

细细考虑可以判断当上界为1下界为4时,可以唯一确定

当手势区域为3*3时并且下界为3,序列中存在7或9时可以唯一确定序列...

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
char a[15];
int b[15];
int u,d,l,r;
int main()
{
scanf("%d",&n);
cin>>a;
u=10;
d=0;
l=10;
r=0;
int flag=0;
for(int i=0;i<n;i++)
b[i]=a[i]-'0';
for(int i=0;i<n;i++)
{
if(b[i]==7||b[i]==9)
flag=1;
if(b[i]==1||b[i]==2||b[i]==3)
{
u=min(u,1);
d=max(d,1);
}
if(b[i]==4||b[i]==5||b[i]==6)
{
u=min(u,2);
d=max(d,2);
}
if(b[i]==7||b[i]==8||b[i]==9)
{
u=min(u,3);
d=max(d,3);
}
if(b[i]==1||b[i]==4||b[i]==7)
{
l=min(l,1);
r=max(r,1);
}
if(b[i]==2||b[i]==5||b[i]==8)
{
l=min(l,2);
r=max(r,2);
}
if(b[i]==3||b[i]==6||b[i]==9)
{
l=min(l,3);
r=max(r,3);
}
if(b[i]==0)
{
l=min(l,2);
r=max(r,2);
u=min(u,4);
d=max(d,4);
}
}
//cout<<u<<" "<<d<<" "<<l<<" "<<r<<endl;
if(d-u==2&&r-l==2&&d==3&&flag==1)
{
cout<<"YES"<<endl;
}
else
{
if(d-u==3)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: