HDU 5641 King's Phone 模拟
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 模拟的更多相关文章
- hdu 5641 King's Phone(暴力模拟题)
Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...
- HDU 5641 King's Phone【模拟】
题意: 给定一串密码, 判断是否合法. 长度不小于4 不能重复经过任何点 不能跳过中间点,除非中间点已经经过一次. 分析: 3*3直接记录出可能出现在两点之间的点,直接模拟就好. 注意审题,别漏了判断 ...
- hdu 5641 King's Phone
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5641 题目类型:水题 题目思路:将点x到点y所需要跨过的点存入mark[x][y]中(无需跨过其它点存 ...
- hdu 5641 BestCoder Round #75
King's Phone Accepts: 310 Submissions: 2980 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- hdu 5640 King's Cake(模拟)
Problem Description It is the king's birthday before the military parade . The ministers prepared ...
- HDU 5640 King's Cake【模拟】
题意: 给定长方形,每次从中切去一个最大的正方形,问最终可以得到多少正方形. 分析: 过程类似求gcd,每次减去最小的边即可. 代码: #include <cstdio> #include ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
随机推荐
- perl6正则 3: 行开头与结尾与多行开头,多行结尾
^ $ 匹配一行的开头或结尾, 可以用 ^ 或 $. > so 'abcde' ~~ /e$/ True > so 'abcdef' ~~ /e$/ False > so 'abcd ...
- 122.Best Time to Buy and Sell Stock II---dp
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/ 题目大意:基本定义与121类似,不 ...
- 55.Jump Game---dp
题目链接 题目大意:给一个数组,第i个位置的值表示当前可以往前走的最远距离,求从第一个位置能否顺利走到最后一个位置.例子如下: 法一(借鉴):DP,dp[i]表示从上一个位置走到当前位置时,剩余的可以 ...
- Windows Phone 8/Windows 8 启动第三方应用程序并传递参数
需要被其他应用启动的第三方应用需要注册protocol association,当一个应用程序启动一个特殊的URI的时候,那么注册了这个protocol的程序会自动启动,并且可以通过这个特殊的URI将 ...
- NTP详解-转
网管实战:Linux时间服务器配置 [IT168 专稿]目前计算机网络中各主机和服务器等网络设备的时间基本处于无序的状态.随着计算机网络应用的不断涌现,计算机的时间同步问题成为愈来愈重要的事情.以Un ...
- [笔记]Linux NTP命令 (ESX适用)
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://delxu.blog.51cto.com/975660/307513 [推荐阅读] ...
- bug-bug-bug
#-*-coding:utf-8-*- import urllib import urllib2 import re import json import threading import reque ...
- c++ 容器学习 理论
[转载]http://blog.csdn.net/acosoft/article/details/4395468 在面向对象的语言中,大多引入了容器的概念.那么 什么 是 容器?实质上就是一组相同类型 ...
- oracle语句练习
1.查看该公司的员工分布在哪几个部门 select distinct deptno from emp; 2.查看每个部门有哪些岗位 select distinct deptno , job from ...
- Java Stream简介, 流的基本概念
在Javaor .net编程中, 我们经常见到"stream" 这个字眼. 我们大概知道这是个流的意思, 如果看完本文的话, 应该会有1个大概的概念. 一, Java中什么是St ...