Simple Robot Gym - 101102I (思维)
SaMer is building a simple robot that can move in the four directions: up (^), down (v), left (<), and right (>). The robot receives the commands to move as a string and executes them sequentially. The robot skips the commands that make it go outside the table.
SaMer has an R×C table and a string of instructions. He wants to place the robot on some cell of the table without rotating it, such that the robot will skip the minimum number of instructions. Can you help him find the number of instructions that will be skipped by the robot if it was placed optimally?
Input
The first line of input contains a single integer T, the number of test cases.
Each test case contains two space-separated integers R and C (1 ≤ R, C ≤ 105), the number of rows and the number of columns in the table, followed by a non-empty string of no more than 200000 characters representing the initial instructions. The instructions are executed in the given order from left to right.
Output
For each test case, print the minimum number of instructions which will be skipped, on a single line.
Example
2
2 2 >^<v>^^<v
3 4 >^<^vv<>v>>v
1
2 题意:
给一个n*m的格子,以及一串移动序列,如果移动超出边界,则会跳过这个操作,问最少会跳过多少个序列(起点未定)
思路:
没必要确定起点,如果在同一方向上走出的距离长度超出了棋盘长度的,那就是要跳过的操作。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); char s[maxn]; int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); int T;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d%d",&n,&m);
scanf("%s",s);
int len=strlen(s);
int x,y;
x=y=;
int x1,x2,y1,y2;
x1=x2=y1=y2=;
int ans=;
for(int i=;i<len;i++){
if(s[i]=='^'){y++;if(y-y1>=n){ans++;y--;continue;}}
else if(s[i]=='v'){y--;if(y2-y>=n){ans++;y++;continue;}}
else if(s[i]=='>'){x++;if(x-x1>=m){ans++;x--;continue;}}
else{
x--;if(x2-x>=m){ans++;x++;continue;}
}
// cout<<i<<" "<<x<<" "<<x1<<endl;
x1=min(x1,x);
x2=max(x2,x);
y1=min(y1,y);
y2=max(y2,y);
}
printf("%d\n",ans);
} return ;
}
/*
5
1 5
>>>>><<<<<
*/
Simple Robot Gym - 101102I (思维)的更多相关文章
- Gym - 101981E 思维
Gym - 101981EEva and Euro coins 题意:给你两个长度皆为n的01串s和t,能做的操作是把连续k个相同的字符反转过来,问s串能不能变成t串. 一开始把相同的漏看了,便以为是 ...
- Problem D. Berland Railroads Gym - 101967D (思维)
题目链接:https://cn.vjudge.net/contest/274029#problem/D 题目大意:给你0-9每个数的个数,然后让你找出最大的数,满足的条件是任意三位相连的都能被三整除. ...
- Mujin Programming Challenge 2017A - Robot Racing【思维题】
题意: 给你n个人的位置,每个人能往后跳一格或两格到无人的位置,跳到0位置,这个人消失,n个人消失组成一个排列,问有多少种排列. 思路: 额,搞了一整场这个A...代码也巨挫了. 处理成1,3,5,7 ...
- Little Difference Gym - 101612L 思维
题意: 给你一个数n,你需要输出它可以由那几个数相乘构成,我们设可以由x个数构成,这x个数中最小值为minn,最大值为maxx,那么要求maxx-minn<=1 问你满足上面要求的情况有多少种. ...
- Equal Numbers Gym - 101612E 思维
题意: 给你n个数vi,你有k次操作.每一次操作你可以从n个数里面挑一个数,然后使得这个数乘于一个正整数.操作完之后,这n个数里面不同数的数量就是权值.你要使得这个值尽可能小. 题解: 如果a%b== ...
- Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维
题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...
- Gazebo機器人仿真學習探索筆記(一)安裝與使用
Gazebo提供了多平臺的安裝和使用支持,大部分主流的linux,Mac以及Windows,這裏結合ROS以Ubuntu爲例進行介紹. 首先是參考資料:http://gazebosim.org/tut ...
- Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...
- codeforce gym/100495/problem/K—Wolf and sheep 两圆求相交面积 与 gym/100495/problem/E—Simple sequence思路简述
之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...
随机推荐
- PHPCMS快速建站系列之网站迁移(本地到服务器,服务器迁移,更换域名等)
可能出现的问题: 1.后台登录验证码显示不正常(修改/caches/configs/system.php文件) //网站路径'web_path' => '/', 2.phpsso修改 如果不修改 ...
- 【Django入坑之路】Django与Query Ajax的交互
1:Jquery.ajax后端交互数据 $.ajax({ Url: /路由处理/, Type: GET/POST, #传送请求类型 Data: {user: “ XXXX”,pass:”XXXX”}, ...
- python 并发之进程
一.什么是进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本执行实 ...
- shell学习(17)- shell中2>&1的解释及输入输出重定向
大多数 UNIX 系统命令从你的终端接受输入并将所产生的输出发送回到您的终端.一个命令通常从一个叫标准输入的地方读取输入,默认情况下,这恰好是你的终端.同样,一个命令通常将其输出写入到标准输出,默 ...
- CPU核数和线程数查找
方法1: 方法2:
- Uva 10446【递推,dp】
UVa 10446 求(n,bcak)递归次数.自己推出来了一个式子: 其实就是这个式子,但是不知道该怎么写,怕递归写法超时.其实直接递推就好,边界条件易得C(0,back)=1.C(1,back)= ...
- ios程序员6级考试(答案和解释)
http://blog.sunnyxx.com/2014/03/06/ios_exam_0_key/ 我是前言 上次发了个ios程序员6级考试题 ,还在不断补充中,开个帖子配套写答案和解释. 1. 下 ...
- oracle函数 UPPER(c1)
[功能]将字符串全部转为大写 [参数]c1,字符表达式 [返回]字符型 [示例] SQL> select upper('AaBbCcDd') upper from dual; UPPER --- ...
- H3C 命令行帮助特性
- PHPstorm相关设置以及快捷键
转自:http://blog.csdn.net/fenglailea/article/details/12166617 1.界面中文方框问题 Settings->Appearance中Theme ...