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

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");
}

转载于:https://www.cnblogs.com/qscqesze/p/5650251.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值