题目链接:

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(1≤k≤9), the password sequence is s1,s2...sk(0≤si<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<T≤100000), 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[],vis[];
int check1()
{
if(k<)return ;
memset(vis,,sizeof(vis));
for(int i=;i<=k;i++)
{
if(a[i]>||a[i]<||vis[a[i]]==)
{
return ;
}
else
{
vis[a[i]]=;
}
}
return ;
}
int check2()
{
memset(vis,,sizeof(vis));
for(int i=;i<k;i++)
{
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
if(a[i]==&&a[i+]==&&vis[]==)return ;
vis[a[i]]=;
}
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&k);
for(int i=;i<=k;i++)
{
scanf("%d",&a[i]);
}
if(check1()==||check2()==)cout<<"invalid"<<"\n";
else cout<<"valid"<<"\n";
}
return ;
}

hdu-5641 King's Phone (水题)的更多相关文章

  1. hdu 5641 King's Phone

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5641 题目类型:水题 题目思路:将点x到点y所需要跨过的点存入mark[x][y]中(无需跨过其它点存 ...

  2. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  3. HDU 5590 ZYB's Biology 水题

    ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  4. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  5. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. hdu 1018:Big Number(水题)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. hdu 2041:超级楼梯(水题,递归)

    超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  8. HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

    Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...

  9. HDOJ(HDU) 2090 算菜价(简单水题、)

    Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...

  10. HDOJ(HDU) 1555 How many days?(水题)

    Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...

随机推荐

  1. Hadoop 101: Programming MapReduce with Native Libraries, Hive, Pig, and Cascading

    和Hadoop交互的四种方法: 1. Native Libraries 2. Hive 3. Pig 4. Cascading At a high level, people use the nati ...

  2. linux php.ini又一次载入问题

    今天发现自己server改动php.ini之后无法又一次载入! .无法使用php-fpm reload,奇怪.! 后来查了一下.能够使用 /etc/init.d/php-fpm reload 来又一次 ...

  3. 1. lvs+keepalived 高可用群集

    一. keepalived 工具介绍 1.专为lvs 和HA 设计的一款健康检查工具 2.支持故障自动切换 3.支持节点健康状态检查 二.  keepalived 实现原理剖析 keepalived ...

  4. JS 创建对象(常见的几种方法)

    贴个代码先: function O(user,pwd){ //use constructor this.user=user; this.pwd=pwd; this.get=get; return th ...

  5. poj3708(公式化简+大数进制装换+线性同余方程组)

    刚看到这个题目,有点被吓到,毕竟自己这么弱. 分析了很久,然后发现m,k都可以唯一的用d进制表示.也就是用一个ai,和很多个bi唯一构成. 这点就是解题的关键了. 之后可以发现每次调用函数f(x),相 ...

  6. swagger api 文档框架

    <其他教程:https://www.cnblogs.com/FlyAway2013/p/7510279.html> 先看看swagger的生态使用图: 其中,红颜色的是swaggger官网 ...

  7. SDOI2012 Round1 day2 集合(set)解题报告

    //=====================以上为官方题解==============// 数据略水,暴力枚举50. 把边按照升序排一遍,在询问,水过. #include<cstdio> ...

  8. (转)关于Http协议,一片就够了

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  9. vs+opencv

    vs + opencv 配置见网页 https://blog.csdn.net/qq_17550379/article/details/78201442 统一所有工程配置见下图:

  10. php类和对象(二)

    面向对象第三大特性:多态 概念: 当父类引用指向子类实例的时候,由于子类对父类函数进行了重写,导致我们在使用该引用取调用相应方法时表现出的不同 条件: 1.必须有继承 2.子类必须对父类的方法进行重写 ...