zoukankan      html  css  js  c++  java
  • codeforces 361 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
    Input
    3
    586
    Output
    NO
    Input
    2
    09
    Output
    NO
    Input
    9
    123456789
    Output
    YES
    Input
    3
    911
    Output
    YES
    原题

     

     

    提示:当当前手势可以左移一个或者右、上、下 ,即代表不唯一,输出NO。暴力判断就好,比如包含1,4,7,0 之一的number就是不可以左移的。如果四个方向都不可移动就是YES。

     

    代码:

     

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    
    using namespace std;
    
    #define  MAX(x,y) (((x)>(y)) ? (x) : (y))
    #define  MIN(x,y) (((x) < (y)) ? (x) : (y))
    #define ABS(x) ((x)>0?(x):-(x))
    
    const int inf = 0x7fffffff;
    const int N=10;
    char a[N];
    int b[N];
    
    int n;
    
    bool can_move_left()
    {
        for(int i=0;i<n; i++){
            if(b[i]==1 ||b[i]==4 ||b[i]==7 ||b[i]==0)
                return false;
        }
        return true;
    }
    
    bool can_move_right()
    {
        for(int i=0;i<n; i++){
            if(b[i]==3 ||b[i]==6 ||b[i]==9 ||b[i]==0)
                return false;
        }
        return true;
    }
    
    bool can_move_up()
    {
        for(int i=0;i<n; i++){
            if(b[i]==1 ||b[i]==2 ||b[i]==3)
                return false;
        }
        return true;
    }
    
    bool can_move_down()
    {
        for(int i=0;i<n; i++){
            if(b[i]==7 ||b[i]==0 ||b[i]==9)
                return false;
        }
        return true;
    }
    
    int main()
    {
    
        cin>>n;
        scanf("%s",a);
        for(int i=0; i<n; i++){
            b[i]=a[i]-'1'+1;
        }
    
        int ok=0;
        if(ok == 0){
            if(can_move_left())       ok=1;
        }
        if(ok == 0){
            if(can_move_right())       ok=1;
        }
        if(ok == 0){
            if(can_move_up())       ok=1;
        }
        if(ok == 0){
            if(can_move_down())       ok=1;
        }
    
    
        printf("%s
    ",ok? "NO":"YES");
    
    
    
    
    
        return 0;
    }

     

  • 相关阅读:
    verilog BRAM 读写
    verilog 语法一 led 翻转
    面试 遇到 问题
    S32K144+UJA1169 (四 ) S32K144 SPI1 功能初始化
    S32K144+UJA1169 ( 三 ) S32K144 SPI1 功能初始化
    S32K144+UJA1169 ( 二 ) S32K144 SPI1 对应的引脚 初始化 为 SPI 功能
    S32K144+UJA1169 ( 一 ) 连接框架+1169 功能 说明
    编译 xboot
    make clean make[1]:sdl2-config:命令未找到
    lwip 内存配置和使用,以及 如何 计算 lwip 使用了多少内存?
  • 原文地址:https://www.cnblogs.com/shawn-ji/p/5661625.html
Copyright © 2011-2022 走看看