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
  • 相关阅读:
    已经有人提出过循环
    中华术数系列之奇门遁甲精简版
    研究下市场上有哪些软件项目/产品,哪些是值得做的?
    中华术数系列之奇门遁甲手机版
    Webbrowser代理支持
    随笔:杂念纷呈
    架构设计实践:基于WCF大型分布式系统(转)
    WCF分布式开发必备知识(3):Enterpise Services(转)
    看完这20部电影 你能变成经济学大师(转)
    WCF服务契约继承与分解设计(转)
  • 原文地址:https://www.cnblogs.com/cshg/p/5306399.html
Copyright © 2011-2022 走看看