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");
        }
    }
  • 相关阅读:
    PC远程调试设备(转)
    根据自己的需要,把别人开发好的东西搬过来,优化and重构,在优化的过程中,甚至也会弄出一套全新的东西(转)
    修改Hosts不生效的一个场景-web 专题
    Data URI(转)
    数据仓库与数据挖掘的一些基本概念
    几种常见模式识别算法整理和总结
    史上最简单的Hibernate入门简单介绍
    sprintf,你知道多少?
    一步一步写算法(之洗牌算法)
    ListView的优化
  • 原文地址:https://www.cnblogs.com/lonewanderer/p/5651537.html
Copyright © 2011-2022 走看看