King's Phone

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5641

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 T(0<T≤100000), the number of the testcases.

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.

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

hint:

For test case #1:The path \(1\rightarrow 3\) skipped the middle point \(2\), so it's invalid.

For test case #2:The path \(1\rightarrow 3\) doesn't skipped the middle point \(2\), because the point 2 has been through, so it's valid.

For test case #2:The path \(8\rightarrow 1 \rightarrow 6 \rightarrow 7\) doesn't have any the middle point \(2\), so it's valid.

Hint

题意

手机锁屏

3*3的格子,需要满足下列四个条件:

1.至少4位密码

2.数字没有重复出现

3.经过的位置之间的数字不能跳过,除非之前经过过。

给你一个串序列,问你是否合法。

题解:

模拟题。

有坑,注意每个数是[0,inf)的……

至少四位数。

注意这些,然后瞎写写就好了。

代码

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<cstring>
using namespace std;
int a[30];
int vis[30];
int check(int x , int y){
if( x > y ) swap( x , y );
if( x == 1 && y == 3) return 2;
else if( x == 1 && y == 7) return 4;
else if( x == 1 && y == 9) return 5;
else if( x == 2 && y == 8) return 5;
else if( x == 3 && y == 9) return 6;
else if( x == 3 && y == 7) return 5;
else if( x == 4 && y == 6) return 5;
else if( x == 7 && y == 9) return 8;
return -1;
} void solve()
{
int flag = 0;
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
if(n<4||n>9)
{
printf("invalid\n");
return;
}
for(int i=1;i<=n;i++)
if(a[i]<=0||a[i]>9)
{
printf("invalid\n");
return;
}
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
{
if(vis[a[i]])
{
printf("invalid\n");
return;
}
vis[a[i]]++;
}
memset(vis,0,sizeof(vis));
for(int i=1;i<n;i++)
{
vis[a[i]]=1;
int p = check(a[i],a[i+1]);
if(p!=-1&&vis[p]==0)
{
printf("invalid\n");
return;
}
}
printf("valid\n");
return;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
return 0;
}

HDU 5641 King's Phone 模拟的更多相关文章

  1. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

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

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

  3. hdu 5641 King's Phone

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

  4. hdu 5641 BestCoder Round #75

    King's Phone  Accepts: 310  Submissions: 2980  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  5. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

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

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

  7. HDU 5640 King's Cake【模拟】

    题意: 给定长方形,每次从中切去一个最大的正方形,问最终可以得到多少正方形. 分析: 过程类似求gcd,每次减去最小的边即可. 代码: #include <cstdio> #include ...

  8. POJ 3344 &amp; HDU 2414 Chessboard Dance(模拟)

    题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...

  9. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

随机推荐

  1. Dijkstra算法(转)

    基本思想 通过Dijkstra计算图G中的最短路径时,需要指定起点s(即从顶点s开始计算). 此外,引进两个集合S和U.S的作用是记录已求出最短路径的顶点(以及相应的最短路径长度),而U则是记录还未求 ...

  2. 发行NEO的NEP-5合约代币

    NEO常见的资产有三种 TOKEN (全局资产) Share (全局资产,股份 ) NEP-5 (合约代币,相当于ETH的ERC20) NEP-5 合约代码 https://github.com/AN ...

  3. MAC和PHY的区别 (转自http://www.cnblogs.com/feitian629/archive/2013/01/25/2876857.html)

    一块以太网网卡包括OSI(开方系统互联)模型的两个层.物理层和数据链路层.物理层定义了数据传送与接收所需要的电与光信号.线路状态.时钟基准.数据编码和电路等,并向数据链路层设备提供标准接口.数据链路层 ...

  4. 64_p8

    python2-cotyledon-tests-1.6.7-2.fc26.noarch.rpm 12-Feb-2017 10:28 23182 python2-couchdb-1.0-6.fc26.n ...

  5. shell视频

    本帖最后由 Shell_HAT 于 2014-04-18 16:51 编辑 尚观全套RHCE视频http://pan.baidu.com/s/1pJvzVR1 马哥网络班-中级视频内容http://p ...

  6. Java显式锁学习总结之五:ReentrantReadWriteLock源码分析

    概述 我们在介绍AbstractQueuedSynchronizer的时候介绍过,AQS支持独占式同步状态获取/释放.共享式同步状态获取/释放两种模式,对应的典型应用分别是ReentrantLock和 ...

  7. java1.8环境配置+win10系统

    Java环境配置相关 Java jdk 1.8版本的环境配置和1.7版本 存在一些差异,当然不同的操作系统可能会对jdk配置有一定的变化.本文我主要说1.8版本的jdk在window10 系统上的配置 ...

  8. Hadoop2.5.2 安装部署

    0x00 平台环境 OS: CentOS-6.5-x86_64 JDK: jdk-8u111-linux-x64 Hadoop: hadoop-2.5.2 0x01 操作系统基本设置 1.1 网络配置 ...

  9. 【58沈剑架构系列】lvs为何不能完全替代DNS轮询

    上一篇文章“一分钟了解负载均衡的一切”引起了不少同学的关注,评论中大家争论的比较多的一个技术点是接入层负载均衡技术,部分同学持这样的观点: 1)nginx前端加入lvs和keepalived可以替代“ ...

  10. 查看loadrunner运行日志

    查看loadrunner运行日志   日志分两种 1.在VUGEN中运行后的日志 2.在controller中运行后的日志日志设置分两步: 1.首先,在VUGEN或controller中run-tim ...