Educational Codeforces Round 128 (Rated for Div. 2)
比赛链接
Educational Codeforces Round 128 (Rated for Div. 2)
B. Robots
There is a field divided into rows and columns. Some cells are empty (denoted as ), other cells contain robots (denoted as ).
You can send a command to all robots at the same time. The command can be of one of the four types:
- move up;
- move right;
- move down;
- move left.
When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.
You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?
Input
The first line contains one integer —— the number of test cases.
Each test case starts with a line containing two integers and —— the number of rows and the number of columns, respectively. Then lines follow; each of them contains a string of characters. Each character is either (empty cell } or (robot).
Additional constraint on the input: in each test case, there is at least one robot on the field.
Output
If it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print YES. Otherwise, print NO.
解题思路
思维
要求左上角出现机器人,则尽量将所有的机器人向左上角移动即可,最后判断左上角是否有机器人,如果向其他方向移动显然只会离答案越来越远
- 时间复杂度:
暴力dfs
直接枚举所有指令,注意不能形成同一局面,否则会无限循环下去,枚举所有局面的复杂度为 ,另外判断是否处于同一局面用到的哈希表的常数过大,需要剪枝:只向左上两个方向移动
注意:这里拷贝恢复现场要用局部变量!
- 时间复杂度:
代码
- 思维
- 暴力dfs
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/16271805.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!