题目链接:

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 ;
}

最新文章

  1. windows CMD下的命令
  2. Linux内核分析总结
  3. 集合框架遍历方式之——for-each循环
  4. 省市县三级联动 sql语句
  5. [麦先生]LINUX常用命令总结
  6. Shell基础:变量类型 &amp; 运算符
  7. 推荐图书-《SQL Server 2008商业智能完美解决方案》
  8. 在Attribute Inspector 上显示自定义的控件的属性
  9. nginx+tomcat+redis完成session共享
  10. 第一个python
  11. php:跨域
  12. ios日期时间
  13. 一张图告诉你什么是Linux distributions...
  14. [CSS3] 学习笔记-CSS选择器
  15. 移动端web总结
  16. Unity与web交互
  17. SSM整合——spring4.*配置案例
  18. mitmdump 屏蔽443错误
  19. Ubuntu 14.04 python3.6 安装
  20. 4. 纯 CSS 创作一个金属光泽 3D 按钮特效

热门文章

  1. bzoj3992【SDOI2015】序列统计
  2. saltstack内置state模块file之append
  3. We7的区县站点群建设策略
  4. maven;tomcat配置
  5. mysql存储过程之事务篇
  6. zoj 2362 Beloved Sons【二分匹配】
  7. Random Fourier Features
  8. python数据分析之:时间序列一
  9. linux 9 -- 交互式使用Bash Shell
  10. 第13条:合理利用try/expect/else/finally结构中的每个代码块