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 × square lattice, the three points in the first line are labeled as ,,, the three points in the second line are labeled as ,,, and the three points in the last line are labeled as ,,。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(≤k≤), the password sequence is s1,s2...sk(≤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(<T≤), 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

 
Sample Output
invalid
valid
valid hint:
For test case #:The path $\rightarrow $ skipped the middle point $$, so it's invalid. For test case #:The path $\rightarrow $ doesn't skipped the middle point $2$, because the point 2 has been through, so it's valid. For test case #:The path $\rightarrow \rightarrow \rightarrow $ doesn't have any the middle point $2$, so it's valid.
 
Source

一个简单的模拟题,首先判断序列长度是否合法,接着判断 sis_is​i​​ 是否在 [1,9],最后扫一遍看看有没有重复以及跨过中间点的情况即可。

复杂度:O(nT)。

AC代码:

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 16
#define inf 1e12
int n;
int a[N],vis[N];
bool judge(int num1,int num2){
if(vis[num2]) return false;
vis[num2]=;
if(num1==){
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
}
if(num1==){
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
if(num2== && vis[]==){
return false;
}
} return true;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
memset(vis,,sizeof(vis));
scanf("%d",&n);
int flag=;
//int num_valid=0;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(a[i]< || a[i]>) flag=;
}
if(flag==){
printf("invalid\n");
continue;
}
flag=;
for(int i=;i<n;i++){
if(vis[a[i]]){
flag=;
break;
}
vis[a[i]]=;
}
if(flag==) {
printf("invalid\n");
continue;
}
if(n<) {
printf("invalid\n");
continue;
}
memset(vis,,sizeof(vis));
vis[a[]]=;
int ok=;
for(int i=;i<n-;i++){
if(judge(a[i],a[i+])==false){
ok=;
break;
}
}
if(ok) printf("valid\n");
else printf("invalid\n");
}
return ;
}

hdu 5641 King's Phone(暴力模拟题)的更多相关文章

  1. HDU 5641 King's Phone【模拟】

    题意: 给定一串密码, 判断是否合法. 长度不小于4 不能重复经过任何点 不能跳过中间点,除非中间点已经经过一次. 分析: 3*3直接记录出可能出现在两点之间的点,直接模拟就好. 注意审题,别漏了判断 ...

  2. HDU 5641 King's Phone 模拟

    King's Phone 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5641 Description In a military parade, ...

  3. hdu 4706:Children's Day(模拟题,模拟输出大写字母 N)

    Children's Day Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 5641 King's Phone

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

  5. hdu 5640 King's Cake(模拟)

    Problem Description   It is the king's birthday before the military parade . The ministers prepared ...

  6. 51nod 1414 冰雕 思路:暴力模拟题

    题意是现在有n个雕像把一个圆等分了,每一个雕像有一个吸引力. 叫你不移动雕像只去掉雕像让剩下的雕像还能等分这个圆,求剩下的雕像的吸引力之和的最大值. 显然去掉后剩下雕像的间隔应该是n的因子,因为这样才 ...

  7. HDU 5059 Help him(简单模拟题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...

  8. HDU 5683 zxa and xor 暴力模拟

    zxa and xor 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5683 Description zxa had a great interes ...

  9. HDU 5486 Difference of Clustering 暴力模拟

    Difference of Clustering HDU - 5486 题意:有n个实体,新旧两种聚类算法,每种算法有很多聚类,在同一算法里,一个实体只属于一个聚类,然后有以下三种模式. 第一种分散, ...

随机推荐

  1. Spring 源码解读 推荐流程

    Spring源代码解析(一):IOC容器:http://www.javaeye.com/topic/86339 Spring源代码解析(二):IoC容器在Web容器中的启动:http://www.ja ...

  2. hdu 5012 Dice

    Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...

  3. HDU 3622 Bomb Game(2-sat)

    HDU 3622 Bomb Game 题目链接 题意:求一个最大半径,使得每一个二元组的点任选一个,能够得到全部圆两两不相交 思路:显然的二分半径,然后2-sat去判定就可以 代码: #include ...

  4. 让你不再纠结GitHub:Git起步

    一.关于版本控制 版本控制是一种记录若干文件内容变化,以便将来查阅特定版本修订情况的系统.我们通常仅对保存着软件源代码的文本文件做版本控制,但实际上,你可以对任何类型的文件进行版本控制. 采用版本控制 ...

  5. 单片机脚本语言-移植lua到stm32-MDK

    Lua简单介绍 Lua[1]  是一个小巧的脚本语言.作者是巴西人.该语言的设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能. Lua脚本能够非常easy的被C/C++ 代码调用, ...

  6. linux 终止用户会话

    第一步使用 tty 命令 查看自己会话id:本例中会话id为1[root@localhost ~]# tty/dev/pts/1[root@localhost ~]# 第二步 使用 w 命令 查看当前 ...

  7. C# 导出Excel 多个Sheet

    以下代码中最关键的代码是 Worksheet mSheet = (Microsoft.Office.Interop.Excel.Worksheet)mBook.Worksheets.Add(miss, ...

  8. 除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。

    在 SELECT 后加 TOP 100 PERCENT .

  9. 网站飘窗js代码

    <SCRIPT> var imagepath="/${res}/images/geren.jpg" ; var imagewidth=178 ;//这两行写图片的大小 ...

  10. asp.net从服务器(指定文件夹)下载任意格式的文件到本地

    一.我需要从服务器下载ppt文件到本地 protected void Btn_DownPPT_Click(object sender, EventArgs e)        {            ...