CodeForces 689AMike and Cellphone(拨号的唯一性)

    xiaoxiao2026-09-20  13

    http://codeforces.com/problemset/problem/689/A

    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.

    题意:

    这题目真是考思维的! 输入手机号码,知道一种形式的输入,问是不是唯一的。

    如 4709 的输入就是唯一的,毕竟找不出那样的一种感觉~~~~~~(自己猜什么感觉)

    思路:

    感觉类分组,只要每个颜色的数字都被选中,就是唯一的!

    Code:

    #include<stdio.h> #include<cstring> const int MYDD=1103; int main() { int n,num[MYDD]; char dd[MYDD]; while(scanf("%d",&n)!=EOF) { scanf("%s",dd); memset(num,0,sizeof(num)); for(int j=0; j<n; j++) num[dd[j]-'0']++;//出现的数字统计 bool a,s,d,f; a=s=d=f=false; if(num[1]||num[4]||num[7]||num[0]) a=true; if(num[1]||num[2]||num[3]) s=true; if(num[3]||num[6]||num[9]||num[0]) d=true; if(num[7]||num[0]||num[9]) f=true; if(a&&s&&d&&f) puts("YES"); else puts("NO"); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1312135.html
    最新回复(0)