HDU 5641
King's Phone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 916 Accepted Submission(s): 261
The pattern interface is a $3 \times 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\le k\le 9)$, the password sequence is $s_1,s_2...s_k(0\le s_{i} < INT\_MAX)$ , he wants to know whether the password is valid. Then the King throws the problem to you.
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 $s_1,s_2...s_k$.
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.
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int t;
int a[];
int mp[][];
map<int,int> mpp;
int jishu=;
void init()
{
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
mp[][]=;
}
int main()
{
scanf("%d",&t); init();
for(int i=;i<=t;i++)
{
scanf("%d",&jishu);
memset(a,,sizeof(a));
int maxn=;
int flag=;
for(int j=;j<=jishu;j++)
{
scanf("%d",&a[j]);
if(a[j]>maxn)
maxn=a[j];
if(a[j]<=)
flag=;
}
mpp.clear();
if(jishu<||jishu>||maxn>||flag==)
printf("invalid\n");
else
{ int re=;
mpp[a[]]=;
for(int j=;j<jishu;j++)
{
if(mpp[a[j+]]==)
{
if(mp[a[j]][a[j+]]==)
re++;
else
{
if(mpp[(a[j]+a[j+])/])
re++;
}
}
mpp[a[j+]]=; }
if(re==jishu-)
printf("valid\n");
else
printf("invalid\n");
}
}
return ;
}
最新文章
- 将Unreal4打包后的工程嵌入到Qt或者桌面中
- iOS tabBar双击事件
- 我所知道的Javascript
- RabbitMQ 工作队列
- Python简介及环境部署
- TCP/IP协议(一)
- pythonchallenge(三)
- MessageBox详解
- java socket编程基础(转)
- Static Classes and Static Class Members
- JXL 读取 Excel java中jxl导出数据到excel的例子 上传文件
- Python重定向到文件
- Facebook-Haystack合并小文件
- 理解spread运算符与rest参数
- 利用 socket 发送 get/post 请求
- H5 54-清空默认边距
- 【MySql】delete用法
- User guide for Netty 4.x
- css样式表--样式表分类
- jquery记录