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个实体,新旧两种聚类算法,每种算法有很多聚类,在同一算法里,一个实体只属于一个聚类,然后有以下三种模式. 第一种分散, ...
随机推荐
- struts配置,略记
<!-- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener ...
- (转载)iOS Framework: Introducing MKNetworkKit
This article is available in Serbo-Croatian, Japanese and German. (Translations in Serbo-Croatian b ...
- [置顶] STM32移植contiki进阶之三(中):timer 中文版
鉴于自己英语水平不高,在这里,将上一篇关于contiki 的timer的文章翻译为中文,让自己在学习的时候,更方便点.文中有许多不是很通顺的地方,将就吧. Timers Contiki系统提供了一套时 ...
- 【hoj】1604 cable master
简单,二分法,可是在oj上交的时候会有精度的限制,所以仅仅能把数扩得大一点,并且在扩的时候为防止尾数会自己主动生成一些非零数,所以还是自己吧扩到的位置设置为0,还有输出时由于%.2lf会自己有4设5入 ...
- resin安装和配置
1 从 http://www.caucho.com/download/ 下载resin 2 检查你的linux环境,查看是否安装了 jdk1.5 或以上版本,是否安装了perl. 输入命令:Java ...
- CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27
CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27 说明: 操作系统:CentOS 6.8 32位 准备篇: 一.系统约定 软件源代码包存放位 ...
- python - 面向对象(二)
类的三大特性 类的三大特性包括: 封装.继承.多态 一.封装 封装就是将类所用到的所有字段.属性.方法都包含在类代码段里面,当实例调用直接调用类中的方法即可. class People(object) ...
- Palindrome Number 回文数
判断一个数字是否是回文数,尝试不用其他额外空间. 注意: 负数也有可能成为回文数吗? 如果你想让int转为string,注意不用其他空间这个约束. 你也可以翻转一个int,但是有可能会溢出. ...
- Oracle语句块PL/SQL循环判断
- --pl/sql Procedural Language /sql --被数据库编译保存,由用户调用 --程序块 /* 语法 Declare – 声明变量 --声明变量 Age int; //没有 ...
- Silverlight visifire Chart图表下载到PPT文件中
一.Silverlight xaml.cs文件 1. //下载图表 private void btnDown_Click(object sender, RoutedEventArgs e ...