HDU 5641 King's Phone 模拟
2016-03-12 22:21
316 查看
King's Phone
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5641Description
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, printvalidif the password is valid, otherwise print
invalid
Sample Input
34 1 3 6 2
4 6 2 1 3
4 8 1 6 7
Sample Output
invalidvalid
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; }
相关文章推荐
- 软件工程实验一 复利计算
- MVC5 条件查询异步刷新
- 利用ESXI-Customizer制作定制化的ESXI
- Info.plist与Prefix.pch修改文件位置遇到的问题及解决方法
- 微软官方提供的免费正版 Windows 8.1/Win10/7/XP/Vista 操作系统虚拟机镜像下载
- Python的多线程和多进程模块对比测试
- 8.定制new和delete
- 多线程同步的原理
- 深入理解JVM—JVM内存模型
- 用户、组及权限管理
- 内核配置与裁剪浅析
- Java学习
- iscroll 5 中文API
- 第二周感悟
- ok6410的madplay配置
- 30道四则运算<2>单元测试
- 【HDU-1863】畅通工程(最小生成树prim)
- Java泛型通配符super使用Demo
- (HADOOP入门)mapreduce入门程序wordcount旧版API
- jquery购物车插件minicart.js