zoukankan      html  css  js  c++  java
  • Grid(规律)

    Grid

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 318  解决: 40
    [提交][状态][讨论版]

    题目描述

    Pong is wandering in the grids, and we take his initial position as (0,0). Each step he can move in the 4 directions of UP, DOWN, LEFT, RIGHT for one grid.
    While we do know some of these steps, we are attacked by Pong’s birds (Pong have birds, maybe) so some steps remain unknown to us. Now we want to be informed how many possible ultimate position he might be.

    输入

    For the first row there is an integer T(T ≤ 100), which is test cases.
    For each case there are 2 rows. First row is an integer n(n ≤ 100000), next row is n operations consists of "UP","DOWN", "LEFT", "RIGHT", "?". Each operation is separated by a space.

    输出

    For each case you should output the answer.

    样例输入

    2
    3
    UP ? LEFT
    4
    ? UP ? RIGHT
    

    样例输出

    4
    9
    

    提示


    因为上下左右确定的就知道终点了,然后就剩下“?”了,所以重点是?的个数,然后就找规律就好了


    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 1000
    #define maxm 100005
    #define rd(x) scanf("%d", &x)
    #define rd2(x, y) scanf("%d%d", &x, &y)
    long long int pk[100500];
    int main()
    {
        int t, n;
        char s[1000000];
        pk[1] = 1;
        pk[0] = 0;
        for(int i = 2; i <= 100005; i++)
            pk[i] = i*4 - 4 + pk[i-2];
        rd(t);
        while(t--){
           rd(n);
           int k = 0;
           getchar();///收回车
           gets(s);  ///不能收回车,但是遇到回车结束
           int len = strlen(s);
           for(int i = 0; i < len; i++){
                if(s[i] == '?') k++;
           }
           printf("%lld
    ", pk[k+1]);
        }
        return 0;
    }
    


  • 相关阅读:
    django 使用form组件提交数据之form表单提交
    django from验证组件
    django中间件
    gin中http重复解析body数据失败
    go 常用工具链
    git 提交规范
    go简单实现heap
    Go优雅实现选传参数
    [已解决]protoc-gen-go: unable to determine Go import path for "xxx.proto"
    Go编译工具命令
  • 原文地址:https://www.cnblogs.com/zswbky/p/8454139.html
Copyright © 2011-2022 走看看