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
  • 相关阅读:
    实现继承的几种方式
    使用 + 操作符、parseInt 、 parseFloat等方法处理数字字符串时的不同
    jQuery插件版无缝轮播,重写了之前的代码,显得更高大上一点
    我是如何从零开始构建一个jsp项目的
    css居中方法详解
    嫌innerHTML性能不够好,推荐几个新方法
    初学事件委托
    Set集合——HashSet、TreeSet、LinkedHashSet(2015年07月06日)
    十大Intellij IDEA快捷键(转)(2015年06月15日)
    IntelliJ IDEA 集成Tomcat后找不到HttpServlet问题(2015年06月13日)
  • 原文地址:https://www.cnblogs.com/cshg/p/5306399.html
Copyright © 2011-2022 走看看