问题 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 ****************************************************************/