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
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.
For each test case, there are only one line. the first first number k,represent the length of the password, then k numbers, separated by a space, representing the password sequence s1,s2...sk.
#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 ;
}
最新文章
- windows CMD下的命令
- Linux内核分析总结
- 集合框架遍历方式之——for-each循环
- 省市县三级联动 sql语句
- [麦先生]LINUX常用命令总结
- Shell基础:变量类型 &; 运算符
- 推荐图书-《SQL Server 2008商业智能完美解决方案》
- 在Attribute Inspector 上显示自定义的控件的属性
- nginx+tomcat+redis完成session共享
- 第一个python
- php:跨域
- ios日期时间
- 一张图告诉你什么是Linux distributions...
- [CSS3] 学习笔记-CSS选择器
- 移动端web总结
- Unity与web交互
- SSM整合——spring4.*配置案例
- mitmdump 屏蔽443错误
- Ubuntu 14.04 python3.6 安装
- 4. 纯 CSS 创作一个金属光泽 3D 按钮特效