DreamGrid creates a programmable robot to explore an infinite two-dimension plane. The robot has a basic instruction sequence and a “repeating parameter” , which together form the full instruction sequence and control the robot.

There are 4 types of valid instructions in total, which are ‘U’ (up), ‘D’ (down), ‘L’ (left) and ‘R’ (right). Assuming that the robot is currently at , the instructions control the robot in the way below:

U: Moves the robot to .
D: Moves the robot to .
L: Moves the robot to .
R: Moves the robot to .
The full instruction sequence can be derived from the following equations
The robot is initially at and executes the instructions in the full instruction sequence one by one. To estimate the exploration procedure, DreamGrid would like to calculate the largest Manhattan distance between the robot and the start point during the execution of the instructions.

Recall that the Manhattan distance between and is defined as .

Input
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:

The first line contains two integers and (), indicating the length of the basic instruction sequence and the repeating parameter.

The second line contains a string (, ), where indicates the -th instruction in the basic instruction sequence.

It’s guaranteed that the sum of of all test cases will not exceed .

Output
For each test case output one line containing one integer indicating the answer.

Sample Input
2
3 3
RUL
1 1000000000
D
Sample Output
4
1000000000
Hint
For the first sample test case, the final instruction sequence is “RULRULRUL” and the route of the robot is (0, 0) - (1, 0) - (1, 1) - (0, 1) - (1, 1) - (1, 2) - (0, 2) - (1, 2) - (1, 3) - (0, 3). It’s obvious that the farthest point on the route is (1, 3) and the answer is 4.

省赛就卡在这道题了,明明不难就是没做出来,甚是难受,现在看看题解当时自己和队友说错了思路,难受。题目大意就是一个机器人重复走一个步骤,问这个机器人移动过程中曼哈顿距离的最大值,曼哈顿距离即两个坐标绝对值的和。

暴力就完事,先按照顺序走完第一遍,之后用乘法来求出第k-1次的位置,再一步一步走完最后一次循环,找出这里面的最大的那个结果即可。

后悔,要是做出来银牌没问题,打星队飘过。

AC代码

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
long long int num[100005];
int main()
{int t;scanf("%d",&t);while(t--){int n,k;long long int maxl=-1;scanf("%d %d",&n,&k);string root;cin>>root;long long int rx=0,ry=0;for(int i=0;i<n;i++){if(root[i]=='R')rx++;if(root[i]=='U')ry--;if(root[i]=='D')ry++;if(root[i]=='L')rx--;maxl=max(maxl,abs(rx)+abs(ry));}rx*=(k-1);ry*=(k-1);for(int i=0;i<n;i++){if(root[i]=='R')rx++;if(root[i]=='U')ry--;if(root[i]=='D')ry++;if(root[i]=='L')rx--;maxl=max(maxl,abs(rx)+abs(ry));}printf("%lld\n",maxl);}return 0;
}

C-Wandering Robot 模拟相关推荐

  1. CodeForces 1463 C. Busy Robot 模拟

    CodeForces 1463 C. Busy Robot 模拟 题目大意: 有一个一维坐标轴,在最初时刻有个机器人位于坐标 0 0 0 位置,有 n n n 个命令,对于每一个命令在 t i t_i ...

  2. JAVA工具篇--java.awt.Robot模拟微信批量添加好友

    前言:java.awt.Robot可以控制鼠标和键盘,本文基于此通过模拟认为添加微信好友的过程实现批量添加微信好友,并最终输出微信号/手机号是否有好友及好友的基本信息,本文代码示例禁用学习交流使用: ...

  3. robot模拟键盘失效

    1. 发现一旦切换程序后,robot无法执行了 请用管理员身份运行 2. 远程登陆最小化或关闭 模拟键盘操作失效 因为通过mstsc启动远程桌面连接时,被连接的Windows会启动一个会话(Sessi ...

  4. ACM-ICPC 2019 山东省省赛 C Wandering Robot

    这个题额,我觉的是一道水题,思维题,需要考虑的情况比较多,题意一个机器人给一条指令,循环n遍,问此过程中离原点最远距离. 考虑最远距离可能出现的的情况. 每次循环之后距离至少为0: 1.假设他每一次循 ...

  5. The 10th Shandong Provincial Collegiate Programming Contest 2019山东省赛游记+解题报告

    比赛结束了几天...这篇博客其实比完就想写了...但是想等补完可做题顺便po上题解... 5.10晚的动车到了济南,没带外套有点凉.酒店还不错. 5.11早上去报道,济南大学好大啊...感觉走了一个世 ...

  6. HHTC_学校集训编程题目(13)(组队赛_3)

    HHTC_学校集训编程题目(13)(组队赛_3) C - Wandering Robot G - Circle B - 迷宫寻宝 D - 给力的移动 E - 谁还不是个宝宝 K - Teamwork ...

  7. Selenium之鼠标和键盘操作及扩展

    概念 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作. ...

  8. 第十届山东省ACM省赛题解

    (ongoing) (holding on) 点击跳转 A - Calandar B - Flipping Game C - Wandering Robot D - Game on a Graph E ...

  9. 总结Selenium WebDriver中一些鼠标和键盘事件的使用

    在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...

最新文章

  1. 值得收藏!16段代码入门Python循环语句
  2. 【保姆级教程】个人深度学习工作站配置指南
  3. 一文看懂:BTS5210G 智能高侧电源开关
  4. css3个性loading,css3 中实现炫酷的loading效果
  5. PHP设计模式练习——制作简单的投诉页面
  6. Leetcode每日一题:104.maximum-depth-of-binary-tree(二叉树的最大深度)
  7. 不知道不 OK!53 个 Python 经典面试题详解
  8. 文件压缩(C#代码)
  9. python简单计算器异常处理_Python计算器(正确除零)
  10. android zlib 和zip,gzip zip 和zlib
  11. 鼎捷软件ERP,MES等系统构筑制造企业信息化系统
  12. 计算机里的文件弄不到桌面怎么办,电脑文件夹在桌面不显示怎么办
  13. react:customize-cra修改webpack配置
  14. 搭建和配置支撑2000人同时观看的流媒体服务器系统(Linux步骤详解)
  15. Aspose.word Java实现html转word,word转html
  16. 强化学习@AAAI2019
  17. 当新三板公司踏入币圈 |链捕手
  18. Ubuntu下Android开发——配置环境,刷机,push
  19. 操作系统:Java模拟CPU调度算法(非抢占短进程优先、可抢占优先权调度、多级反馈队列调度)
  20. Java安全攻防之从wsProxy到AbstractTranslet

热门文章

  1. Erlang打包工具rebar安装使用
  2. ROW_NUMBER() OVER()函数用法详解
  3. Roundcube Webmail跨站脚本漏洞(CVE-2015-5381 )
  4. Codevs 2460 == BZOJ 1036 树的统计
  5. 直接拿来用!最火的Android开源项目(一) (转)
  6. JavaScript高级程序设计33.pdf
  7. 我的职业规划,大家给点意见吧!
  8. 【PyQt5】PyQt5 安装 以及使用 designer 开发 python GUI 界面
  9. Eclipse的设置、调优、使用(解决启动卡顿等问题)
  10. 设计模式13_享元模式