zoukankan      html  css  js  c++  java
  • Codeforces Round #361 (Div. 2) A. Mike and Cellphone

    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.

    智商不够,暴力来凑_(:з」∠)_

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <map>
    #include <utility>
    #define MP(x, y) make_pair(x, y);
    using namespace std;
    char num[10];
    map< int, pair<int, int> > mp;
    vector< pair<int, int> > vec;
    map< pair<int, int>, pair<int, int> > mp2;
    
    bool check(int x, int y) {
        if((x >= 1 && x <= 3 && y >= 1 && y <= 3) || (x == 2 && y == 4)) return true;
        return false;
    }
    
    int main() {
        int n;
        int cnt = 0;
        for(int i = 1; i <= 3; i++) {
            for(int j = 1; j <= 3; j++) {
                ++cnt;
                mp[cnt] = MP(i, j);
            }
        }
        mp[0] = MP(4, 2);
        for(int i = 0; i <= 9; i++) {
            for(int j = 0; j <= 9; j++) {
                pair<int, int> p;
                pair<int, int> p2;
                p = MP(i, j);
                p2 = make_pair(mp[j].first - mp[i].first, mp[j].second - mp[i].second);
                mp2[p] = p2;
            }
        }
    
        while(~scanf("%d", &n)) {
            scanf("%s", num);
            int len = strlen(num);
            for(int i = 0; i < len - 1; i++) {
                int tmpa = num[i] - '0';
                int tmpb = num[i + 1] - '0';
                pair<int, int> p;
                p = MP(tmpa, tmpb);
                vec.push_back(mp2[p]);
            }
            int cnt = 0;
            for(int i = 1; i <= 4; i++) {
                for(int j = 1; j <= 3; j++) {
                    int flag = 1;
                    int nowx = j, nowy = i;
                    for(int k = 0; k < vec.size(); k++) {
                        if(!check(nowx, nowy)) {
                            flag = 0; break;
                        }
                        nowy += vec[k].first;
                        nowx += vec[k].second;
                        if(!check(nowx, nowy)) {
                            flag = 0;
                            break;
                        }
                    }
                    if(flag) cnt++;
                }
            }
            if(cnt >= 2) puts("NO");
            else puts("YES");
        }
    }
  • 相关阅读:
    git在iOS开发中的使用
    搜索联系人是去掉拼音中的空格
    xmPP(即时通讯)向远程服务器请求数据
    使用CFStringTransform进行汉字转拼音(可去掉声调)
    node的模块系统和commonJS规范的关系
    在centos7中通过使用yum安装mongoDB
    vue跨组件通信,简易状态管理的使用
    Linux(centos7) 常用命令
    前端打包后, 路由模式为history时,用express测试服务端能否正常解析路由路径
    几个文件目录树生成工具tree,treer,tree-cli,tree-node-cli的使用配置和对比
  • 原文地址:https://www.cnblogs.com/lonewanderer/p/5651537.html
Copyright © 2011-2022 走看看