zoukankan      html  css  js  c++  java
  • hdu-5641 King's Phone (水题)

    题目链接:

    King's Phone

    Time Limit: 2000/1000 MS (Java/Others)   

     Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 418    Accepted Submission(s): 123


    Problem Description
    In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen.

    The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as 1,2,3, the three points in the second line are labeled as 4,5,6, and the three points in the last line are labeled as 7,8,9。The password itself is a sequence, representing the points in chronological sequence, but you should follow the following rules:

    - The password contains at least four points.


    - Once a point has been passed through. It can't be passed through again.

    - The middle point on the path can't be skipped, unless it has been passed through(3427 is valid, but 3724 is invalid).

    His password has a length for a positive integer k(1k9), the password sequence is s1,s2...sk(0si<INT_MAX) , he wants to know whether the password is valid. Then the King throws the problem to you.
     
    Input
    The first line contains a number&nbsp;T(0<T100000), the number of the testcases.

    For each test case, there are only one line. the first first number&nbsp;k,represent the length of the password, then k numbers, separated by a space, representing the password sequence s1,s2...sk.
     
    Output
    Output exactly T lines. For each test case, print `valid` if the password is valid, otherwise print `invalid`
     
    Sample Input
    3
    4 1 3 6 2
    4 6 2 1 3
    4 8 1 6 7
     
    Sample Output
    invalid
    valid
    valid
    AC代码:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int k,a[12],vis[12];
    int check1()
    {
        if(k<4)return 0;
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=k;i++)
        {
            if(a[i]>9||a[i]<1||vis[a[i]]==1)
            {
                return 0;
            }
            else
            {
                vis[a[i]]=1;
            }
        }
        return 1;
    }
    int check2()
    {
        memset(vis,0,sizeof(vis));
        for(int i=1;i<k;i++)
        {
            if(a[i]==1&&a[i+1]==3&&vis[2]==0)return 0;
            if(a[i]==3&&a[i+1]==1&&vis[2]==0)return 0;
            if(a[i]==1&&a[i+1]==7&&vis[4]==0)return 0;
            if(a[i]==7&&a[i+1]==1&&vis[4]==0)return 0;
            if(a[i]==1&&a[i+1]==9&&vis[5]==0)return 0;
            if(a[i]==9&&a[i+1]==1&&vis[5]==0)return 0;
            if(a[i]==3&&a[i+1]==9&&vis[6]==0)return 0;
            if(a[i]==9&&a[i+1]==3&&vis[6]==0)return 0;
            if(a[i]==7&&a[i+1]==3&&vis[5]==0)return 0;
            if(a[i]==3&&a[i+1]==7&&vis[5]==0)return 0;
            if(a[i]==7&&a[i+1]==9&&vis[8]==0)return 0;
            if(a[i]==9&&a[i+1]==7&&vis[8]==0)return 0;
            if(a[i]==4&&a[i+1]==6&&vis[5]==0)return 0;
            if(a[i]==6&&a[i+1]==4&&vis[5]==0)return 0;
            if(a[i]==2&&a[i+1]==8&&vis[5]==0)return 0;
            if(a[i]==8&&a[i+1]==2&&vis[5]==0)return 0;
            vis[a[i]]=1;
        }
        return 1;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&k);
            for(int i=1;i<=k;i++)
            {
                scanf("%d",&a[i]);
            }
            if(check1()==0||check2()==0)cout<<"invalid"<<"
    ";
            else cout<<"valid"<<"
    ";
        }
        return 0;
    }
  • 相关阅读:
    调试
    node笔记汇总
    移动端布局
    css 易错点总结
    Angular笔记
    CANVAS笔记
    http笔记汇总
    各种环境搭建 软件安装等等 参考网址收录
    js中同步异步,任务队列
    node.js之fs模块
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5270835.html
Copyright © 2011-2022 走看看