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思路简述
之前几乎没写过什么这种几何的计算题.在众多大佬的博客下终于记起来了当时的公式.嘚赶快补计算几何和概率论的坑了... 这题的要求,在对两圆相交的板子略做修改后,很容易实现.这里直接给出代码.重点的部分有 ...
随机推荐
- [idea]Error:java: invalid source release: 1.8 标签: idea 2017-02-24 15:50 961人阅读
最近用idea敲struts,虽然idea的界面很好看,代码提示也很强大,不过也的确是碰到了一些在eclipse上从来没有碰到过的问题,而且我发现,idea的错误,很多都是在外国的网站上提问的人比较多 ...
- 基于OPNET的路由协议仿真教程(AODV、OLSR 、DSR等)
前言: 目前由于项目需要,学习了基于opnet的网络仿真方法,发现该软件的学习资料少之又少,所以将自己搜集到的学习资料进行整理,希望能帮助后来的人. 主要参考资料:OPNET网络仿真(清华陈敏版) 仿 ...
- mysql锁机制之表锁(三)
顾名思义,表锁就是一锁锁一整张表,在表被锁定期间,其他事务不能对该表进行操作,必须等当前表的锁被释放后才能进行操作.表锁响应的是非索引字段,即全表扫描,全表扫描时锁定整张表,sql语句可以通过执行计划 ...
- PB 级数据处理挑战,Kubernetes如何助力基因分析?
摘要: 一家大型基因测序功能公司每日会产生 10TB 到 100TB 的下机数据,大数据生信分析平台需要达到 PB 级别的数据处理能力.这背后是生物科技和计算机科技的双向支撑:测序应用从科研逐步走向临 ...
- Python学习之路3☞编程风格
语句和语法 # 表示注释掉的内容 \ 续行 print("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\ yyyyyyyyyyyyyyyyyyyyyyy& ...
- KiCad EDA 5.1.3 正式发布了
KiCad EDA 是一款用于印刷电路板设计的开源自由软件,最初由法国人 Jean-Pierre Charras 于 1992 年推出1,现由 KiCad 开发团队维护. KiCad 目前支持英语.法 ...
- 国内 PHP Composer 镜像列表(2019-07-07)
目录 国内 PHP Composer 镜像列表 Composer 是什么? 镜像列表 配置镜像 本文历史 参考 国内 PHP Composer 镜像列表 Composer 是什么? Composer ...
- C++运行时类型识别
通过运行时类型识别(RTTI),程序能够使用基类的指针或引用来检索这些指针或引用所指对象的实际派生类型. 通过下面两个操作符提供 RTTI: 1. typeid 操作符,返回指针或引用所指对象的实际类 ...
- Calendar类实现当前日期的日历
package com.sxt.home1; import java.text.DateFormat; import java.text.ParseException; import java.tex ...
- 2015 Objective-C 三大新特性
http://www.cocoachina.com/ios/20150617/12148.html Overview 自 WWDC 2015 推出和开源 Swift 2.0 后,大家对 Swift 的 ...