hdu-5641 King ' s Phone (water problem)

Source: Internet
Author: User

Topic Links:

King ' s Phone

Time limit:2000/1000 MS (java/others)

Memory limit:65536/65536 K (java/others)
Total submission (s): 418 Accepted Submission (s): 123


Problem DescriptionIn 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 a3x3 Square lattice, the three points in the first line is labeled as1,2,3 , the three points in the second line is labeled as4,5,6 , and the three points in the last line is labeled as7,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 is skipped, unless it has been passed through (3427is valid, but3724is invalid).

His password have a length for a positive integerk(1≤k≤9) , the password sequence isS1,S2..s K (0 ≤ Si<int_< Span id= "mathjax-span-71" class= "Mi" >ma x) , he wants to know whether the password is valid. Then the King throws the problem.

Inputthe first line contains a number&nbsp;T(0<t≤100000) , the number of the testcases.

For each test case, there is only one line. The first first number&nbsp;k, represent the length of the password, thenkNumbers, separated by a space, representing the password sequence s1,s2.. . sk.

Outputoutput exactly T lines. For each test case, print ' valid ' If the password is valid, otherwise print ' invalid '

Sample Input34 1 3 6 24 6 2 1 34 8 1 6 7

Sample OUTPUTINVALIDVALIDVALIDAC Code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;intk,a[ A],vis[ A];intCheck1 () {if(k<4)return 0; memset (Vis,0,sizeof(VIS));  for(intI=1; i<=k;i++)    {        if(a[i]>9|| a[i]<1|| vis[a[i]]==1)        {            return 0; }        Else{Vis[a[i]]=1; }    }    return 1;}intCheck2 () {memset (Vis,0,sizeof(VIS));  for(intI=1; i<k;i++)    {        if(a[i]==1&&a[i+1]==3&&vis[2]==0)return 0; if(a[i]==3&&a[i+1]==1&&vis[2]==0)return 0; if(a[i]==1&&a[i+1]==7&&vis[4]==0)return 0; if(a[i]==7&&a[i+1]==1&&vis[4]==0)return 0; if(a[i]==1&&a[i+1]==9&&vis[5]==0)return 0; if(a[i]==9&&a[i+1]==1&&vis[5]==0)return 0; if(a[i]==3&&a[i+1]==9&&vis[6]==0)return 0; if(a[i]==9&&a[i+1]==3&&vis[6]==0)return 0; if(a[i]==7&&a[i+1]==3&&vis[5]==0)return 0; if(a[i]==3&&a[i+1]==7&&vis[5]==0)return 0; if(a[i]==7&&a[i+1]==9&&vis[8]==0)return 0; if(a[i]==9&&a[i+1]==7&&vis[8]==0)return 0; if(a[i]==4&&a[i+1]==6&&vis[5]==0)return 0; if(a[i]==6&&a[i+1]==4&&vis[5]==0)return 0; if(a[i]==2&&a[i+1]==8&&vis[5]==0)return 0; if(a[i]==8&&a[i+1]==2&&vis[5]==0)return 0; Vis[a[i]]=1; }    return 1;}intMain () {intT; scanf ("%d",&t);  while(t--) {scanf ("%d",&k);  for(intI=1; i<=k;i++) {scanf ("%d",&A[i]); }        if(Check1 () = =0|| Check2 () = =0) cout<<"Invalid"<<"\ n"; Elsecout<<"valid"<<"\ n"; }    return 0;}

hdu-5641 King ' s Phone (water problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.