zoukankan      html  css  js  c++  java
  • Codeforces Round #361 (Div. 2) 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.

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

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

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

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

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 using namespace std;
     6 int n;
     7 char a[15];
     8 int b[15];
     9 int u,d,l,r;
    10 int main()
    11 {
    12     scanf("%d",&n);
    13     cin>>a;
    14     u=10;
    15     d=0;
    16     l=10;
    17     r=0;
    18     int flag=0;
    19     for(int i=0;i<n;i++)
    20         b[i]=a[i]-'0';
    21     for(int i=0;i<n;i++)
    22     {
    23         if(b[i]==7||b[i]==9)
    24             flag=1;
    25         if(b[i]==1||b[i]==2||b[i]==3)
    26         {
    27             u=min(u,1);
    28             d=max(d,1);
    29         }
    30         if(b[i]==4||b[i]==5||b[i]==6)
    31         {
    32              u=min(u,2);
    33              d=max(d,2);
    34         }
    35         if(b[i]==7||b[i]==8||b[i]==9)
    36         {
    37              u=min(u,3);
    38              d=max(d,3);
    39         }
    40         if(b[i]==1||b[i]==4||b[i]==7)
    41         {
    42             l=min(l,1);
    43             r=max(r,1);
    44         }
    45         if(b[i]==2||b[i]==5||b[i]==8)
    46         {
    47             l=min(l,2);
    48             r=max(r,2);
    49         }
    50         if(b[i]==3||b[i]==6||b[i]==9)
    51         {
    52             l=min(l,3);
    53             r=max(r,3);
    54         }
    55         if(b[i]==0)
    56         {
    57             l=min(l,2);
    58             r=max(r,2);
    59             u=min(u,4);
    60             d=max(d,4);
    61         }
    62     }
    63     //cout<<u<<" "<<d<<" "<<l<<" "<<r<<endl;
    64        if(d-u==2&&r-l==2&&d==3&&flag==1)
    65        {
    66            cout<<"YES"<<endl;
    67        }
    68        else
    69        {
    70            if(d-u==3)
    71             cout<<"YES"<<endl;
    72            else
    73             cout<<"NO"<<endl;
    74 
    75        }
    76     return 0;
    77 }
  • 相关阅读:
    DB2隔离级别之RR/RS/CS/UR
    struts1之工作原理
    CSS之伪类
    JSF+EJB+JPA之整体思想
    microservice-cloud-03-provider-product-8001
    在SpringCloud中MAVEN配置文件中的更改
    springBoot和MyBatis整合中出现SpringBoot无法启动时处理方式
    使用springBoot和mybatis整合时出现如下错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)解决方案
    application.properties
    springboot
  • 原文地址:https://www.cnblogs.com/hsd-/p/5657118.html
Copyright © 2011-2022 走看看