hdu 5641 King's Phone(暴力模拟题)
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.
The first line contains a number T(<T≤), 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 exactly T lines. For each test case, print `valid` if the password is valid, otherwise print `invalid`
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.
一个简单的模拟题,首先判断序列长度是否合法,接着判断 sis_isi 是否在 [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(暴力模拟题)的更多相关文章
- HDU 5641 King's Phone【模拟】
题意: 给定一串密码, 判断是否合法. 长度不小于4 不能重复经过任何点 不能跳过中间点,除非中间点已经经过一次. 分析: 3*3直接记录出可能出现在两点之间的点,直接模拟就好. 注意审题,别漏了判断 ...
- HDU 5641 King's Phone 模拟
King's Phone 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5641 Description In a military parade, ...
- hdu 4706:Children's Day(模拟题,模拟输出大写字母 N)
Children's Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 5641 King's Phone
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5641 题目类型:水题 题目思路:将点x到点y所需要跨过的点存入mark[x][y]中(无需跨过其它点存 ...
- hdu 5640 King's Cake(模拟)
Problem Description It is the king's birthday before the military parade . The ministers prepared ...
- 51nod 1414 冰雕 思路:暴力模拟题
题意是现在有n个雕像把一个圆等分了,每一个雕像有一个吸引力. 叫你不移动雕像只去掉雕像让剩下的雕像还能等分这个圆,求剩下的雕像的吸引力之和的最大值. 显然去掉后剩下雕像的间隔应该是n的因子,因为这样才 ...
- HDU 5059 Help him(简单模拟题)
http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...
- HDU 5683 zxa and xor 暴力模拟
zxa and xor 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5683 Description zxa had a great interes ...
- HDU 5486 Difference of Clustering 暴力模拟
Difference of Clustering HDU - 5486 题意:有n个实体,新旧两种聚类算法,每种算法有很多聚类,在同一算法里,一个实体只属于一个聚类,然后有以下三种模式. 第一种分散, ...
随机推荐
- 论 <%@taglib prefix="s" uri="/struts-tags" %> 的重要性
前段时间在做项目的时候,碰到这个问题 结果是相应的内容显示不出来,原来是忘了这句很关键的引入:<%@taglib prefix="s" uri="/struts-t ...
- [转]用Node.js创建自签名的HTTPS服务器
用Node.js创建自签名的HTTPS服务器 创建自己的CA机构 创建服务器端证书 创建客户端证书 将证书打包 创建自己的CA机构 为CA生成私钥 openssl genrsa -out ca-key ...
- [Javascript] Call Stack
Every time when a function run it will be push into the call stack and put on the top, you can thin ...
- tomcat线程数查看
获取tomcat进程pid ps -ef|grep tomcat 统计该tomcat进程内的线程个数 ps -Lf 29295 |wc -l
- [转]iOS开发使用半透明模糊效果方法整理
转自:http://www.molotang.com/articles/1921.html 虽然iOS很早就支持使用模糊效果对图片等进行处理,但尤其在iOS7以后,半透明模糊效果得到大范围广泛使用.包 ...
- 只包含schema的dll生成和引用方法
工作中,所有的tools里有一个project是只包含若干个schema的工程,研究了一下,发现创建这种只包含schema的dll其实非常简单. 首先,在visual studio-new proje ...
- android-用xml自定义背景(可自定义显示具体那一边)
常见的描边都是闭合的.四个边都有.如下: <?xml version="1.0" encoding="UTF-8"?> <layer-list ...
- update-database时出现Cannot attach the file
在进行Migrations时,如果直接删除了Db文件,在使用update-database时会出现Cannot attach the file发问题 解决方案:
- sharding的基本思想和理论上的切分策略
本文着重介绍sharding的基本思想和理论上的切分策略,关于更加细致的实施策略和参考事例请参考我的另一篇博文:数据库分库分表(sharding)系列(一) 拆分实施策略和示例演示 一.基本思想 Sh ...
- C#三个平台上的文件选择方法
wpf: Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = &qu ...