zoukankan      html  css  js  c++  java
  • hdoj-5641 king's phone

    Problem 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 asquare 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(1k9), the password sequence is s1,s2...sk(0si<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&nbsp;T(0<T100000), the number of the testcases.

    For each test case, there are only one line. the first first number&nbsp;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 ightarrow 3$ skipped the middle point $2$, so it's invalid. For test case #2:The path $1 ightarrow 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 ightarrow 1 ightarrow 6 ightarrow 7$ doesn't have any the middle point $2$, so it's valid.

    这个题挺坑的,首先给的数据不安规则出牌,这也是我们平时难以想到的。比如吧,给的密码的个数可能大于9个,

    密码可能比1 小比9大。。其他的不说了,知道这些相信你也会做。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
     
    using namespace std;
     
    const int N = 2;
    int slove(int m, int n){
        if(m == 0 || n == 1) return 1;
        if(m < n ) return slove(m,m);
        return slove(m-n, n)+slove(m,n-1);
     
    }
    int main() {
        int t,m,n;
        scanf("%d", &t);
        while(t--) {
            scanf("%d%d", &m, &n);
           printf("%d
    ",slove(m,n));
        }
        return 0;
    }
    View Code
  • 相关阅读:
    spark 随意笔记
    c#读取输入字符串,从数据源中查找以该字符串开头的所有字符串(使用正则表达式)
    我的收藏链接地址
    SQL查询时,遇到用到关键词作的字段。将该字段用一对中括号括起来[]
    SQL数据类型相互转换
    Javascript获取系统当前时间
    节点类型nodeType的取值
    混合布局编程挑战
    Webstorm破解方法
    二列布局
  • 原文地址:https://www.cnblogs.com/cshg/p/5306399.html
Copyright © 2011-2022 走看看