题目链接:

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. react-native create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理

    SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' 错误 ...

  2. 博弈SG函数

    转自:Sprague-Grundy Function-SG函数--博弈论(3) 公平游戏的Sprague-Grundy定理 公平游戏是一种双人游戏,在游戏中双方都有完整的信息,没有牵涉,任何状态的合法 ...

  3. Netty实现java多线程Post请求解析(Map参数类型)—SKY

    netty解析Post的键值对 解析时必须加上一个方法,ch.pipeline().addLast(new HttpObjectAggregator(2048)); 放在自己的Handel前面. ht ...

  4. 九度OJ 1339:ACM (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:712 解决:379 题目描述: 今年的ACM世界总决赛快要开始了,需要有一个排名算法来对每支队伍进行现场排名.ACM组委会把这个任务交给了你 ...

  5. 九度OJ 1336:液晶屏裁剪 (GCD)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:983 解决:228 题目描述: 苏州某液晶厂一直生产a * b大小规格的液晶屏幕,由于该厂的加工工艺限制,液晶屏的边长都为整数.最近由于市场 ...

  6. On the importance of initialization and momentum in deep learning

    Ilya Sutskever1 ilyasu@google.com James Martens jmartens@cs.toronto.edu George Dahl gdahl@cs.toronto ...

  7. vue v-on命令

    <!-- 阻止单击事件冒泡 --> <a v-on:click.stop="doThis"></a>   <!-- 提交事件不再重载页面 ...

  8. setTimeout解决循环值的几种方法

    for(var i=0;i<5;i++){ setTimeout(function(){ console.log(`错误 ${i}`); },0) } for(var i=0;i<5;i+ ...

  9. 图片的等比缩放和Logo水印

    /** * 等比缩放函数(以保存的方式实现) * @param string $picname 被缩放的处理图片源 * @param int $maxx 缩放后图片的最大宽度 * @param int ...

  10. iOS 读取本地Json文件

    之前写过类似的方法 今天写这个 的目的是 应对开发过程中面对 服务端数据刚定下模型 但是接口不通 的情况下 不耽误客户端开发进度 + (id)getJsonDataJsonname:(NSString ...