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");
        }
    }
  • 相关阅读:
    关于JQ中,新生成的节点on绑定事件失效的解决
    免费获取SSL证书/一键安装SSL证书/https加密
    在github上面创建新的分支
    github-新建文件夹
    如何删除github上的某个文件夹
    FTP连接虚拟主机响应220 Welcome to www.net.cn FTP service. (解决的一个问题)
    两种方法上传本地文件到github(转)
    Windows下如何将一个文件夹通过Git上传到GitHub上(转)
    利用Github免费搭建个人主页(转)
    关于阿里ICON矢量图(SVG)上传问题.
  • 原文地址:https://www.cnblogs.com/lonewanderer/p/5651537.html
Copyright © 2011-2022 走看看