zoukankan      html  css  js  c++  java
  • CodeForces 689A Mike and Cellphone (模拟+水题)

    Mike and Cellphone

    题目链接:

    http://acm.hust.edu.cn/vjudge/contest/121333#problem/E

    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

    题意:

    判断是否有路径形状一致的按键序列;

    题解:

    正确建坐标系来量化各按键间的转移过程,暴力求解;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<queue>
    #include<set>
    #include<list>
    #define LL long long
    #define maxn 210000
    #define inf 0x3f3f3f3f
    #define IN freopen("in.txt","r",stdin);
    #define OUT freopen("out.txt","w",stdout);
    using namespace std;
    
    int n;
    struct node{
        int x,y;
    };
    node pos[] = {{2,4},{1,1},{2,1},{3,1},{1,2},{2,2},{3,2},{1,3},{2,3},{3,3}};
    int path[15];
    
    bool is_ok(int x,int y) {
        if(x==1&&y==4 || x==3&&y==4) return 0;
        return x>=1&&x<=3&&y>=1&&y<=4;
    }
    
    int main(int argc, char const *argv[])
    {
       //IN;
    
        while(scanf("%d",&n) != EOF)
        {
            getchar();
            for(int i=1; i<=n; i++){
                int c = getchar();
                path[i] = c-'0';
            }
    
            int flag = 1;
            for(int i=0; i<=9; i++){
                if(i == path[1]) continue;
                flag = 1;
                int curx = pos[i].x;
                int cury = pos[i].y;
                for(int j=2; j<=n; j++){
                    int dx = pos[path[j]].x - pos[path[j-1]].x;
                    int dy = pos[path[j]].y - pos[path[j-1]].y;
                    curx += dx; cury += dy;
                    if(!is_ok(curx,cury)) {flag=0;break;}
                }
                if(flag) {puts("NO");break;}
            }
    
            if(!flag) puts("YES");
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    ubuntu使用su切换root用户时认证失败的解决方法
    IntelliJ IDEA编辑文件的时候CPU飙高问题的解决
    postgreSQL数据类型转换字符串和数值
    java生成图片验证码二,加入透明颜色,各种干扰线,干扰点,干扰框,旋转,随机位置
    Burpsuite Response返回中文乱码问题
    postgre with递归查询组织路径
    java.lang.UnsupportedOperationException 异常分析,List<String> natureList = new ArrayList<>(Arrays.asList(patternSplit));
    js比较时间大于6个月
    将旧版本jQuery升级到新版本的jQuery
    java只允许输入数字字母下划线中文
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5693286.html
Copyright © 2011-2022 走看看