2017年省赛前最后一水---K题

问题 K: Grid
时间限制: 1 Sec 内存限制: 128 MB
提交: 322 解决: 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

递推出结果,写4个就可以出来了,不需要知道顺序,只要得到‘?’的个数就行

#include<stdio.h>

#include<string.h>



char s1[700005];
int main(){

    int t;
    int i;
    long long  n;
    while(~scanf("%d",&t)){
        while(t--){
            memset(s1,0,sizeof(s1));
            scanf("%lld",&n);
            getchar();
            gets(s1);
            long long count=0;
            int len = strlen(s1);
            for(int i=0;i<len;i++)
            {
                if(s1[i]=='?')
                {
                    count++;
                }
            }
            printf("%lld\n",(count+1)*(count+1));
        }
    }
        return 0;
}
/**************************************************************
    Problem: 1022
    User: T032
    Language: C++
    Result: 正确
    Time:644 ms
    Memory:1644 kb
****************************************************************/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值