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. JAVA获取oracle中sequences的最后一个值

    项目中,用到一个序列作单号,框架用的是ssh,在dao层去拿的时候,运行时报错为dual is not mapped,[select *.nextval nextvalue from dual] 后来 ...

  2. hdu 4666 Hyperspace

    曼哈顿距离,两个点设为(x1,y1),(x2,y2),其距离为|x1-x2|+|y1-y2| #include <cstdio> #include <set> #include ...

  3. Swift 2.0初探:值得注意的新特性

    转眼间,Swift已经一岁多了,这门新鲜.语法时尚.类型安全.执行速度更快的语言已经渐渐的深入广大开发者的心.我同样也是非常喜爱这门新的编程语言. 今年6月,一年一度的WWDC大会如期而至,在大会上A ...

  4. 阿里云 RDS 怎么保证高可用性

    RDS在系统构建之初,从网络到硬件再到系统都是基于高可用设计,他可以做到故障30秒无缝转移,对应用完全透明. 当一个数据库实例发生故障时, 另一个会立即顶上,而且对应用是完全透明的.你无需变更应用的连 ...

  5. (转)Javascript面向对象编程(二):构造函数的继承(作者:阮一峰)

    对象之间的"继承"的五种方法. 比如,现在有一个"动物"对象的构造函数. function Animal(){ this.species = "动物& ...

  6. Android-------------获取手机IP地址

    ##帮助类PhoneNetStateUtil package com.funs.PhoneIPAddress.utils; /**      * 手机联网状态工具类 需要的权限 WIFI时:</ ...

  7. 微软HoloLens虚拟现实可以开发了。

    1.microsoft-hololens-now-available-to-developers 2.http://www.microsoft.com/microsoft-hololens/en-us ...

  8. trailingZeroes

    Given an integer n, return the number of trailing zeroes in n!. 给一个数字n,返回它n!数字后面有多少个0. public class ...

  9. hdu4006 优先队列

    A - 签到 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65768KB     64bit I ...

  10. (原)ubuntu16重装显卡驱动后,torch中的问题

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6030232.html 参考网址: https://github.com/torch/cutorch/i ...