TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
来源:互联网 发布:阿里云cdn协议跟随 编辑:程序博客网 时间:2024/06/06 00:58
题意
两个机器人一开始在不同的坐标,有一个上下左右的指令序列,他们可以按顺序任意执行一些指令,问有没有可能到同一个地方。
思路
一般都会先想到记录一下两只机器人能走过的地方,如果有重复就能爆炸。
然而指令长度为50,这样需要
注意到X和Y相距很小,那么我们可以枚举一只机器人理论上能活动的每一个点,看看第二只能不能到这个点。
判断的方法很简单,看看那只机器人到这个点需要几步方向即可。
然后我们一开始预处理一下每个方向的数量。
代码
class ExplodingRobots {public: int num[5] = {0}; bool can_arrive(int needx, int needy) { //0123 上下左右 if (needx < 0) { if (num[2] < -needx) return false; } else { if (num[3] < needx) return false; } if (needy < 0) { if (num[1] < -needy) return false; } else { if (num[0] < needy) return false; } return true; } string canExplode(int x1, int y1, int x2, int y2, string instructions) { for (char cmd : instructions) { if (cmd == 'U') ++num[0]; else if (cmd == 'D') ++num[1]; else if (cmd == 'L') ++num[2]; else ++num[3]; } int left = x1 - 50, right = x1 + 50; int up = y1 + 50, down = y1 - 50; for (int x = left; x <= right; ++x) { for (int y = down; y <= up; ++y) { if (can_arrive(x - x1, y - y1) && can_arrive(x - x2, y - y2)) return "Explosion"; } } return "Safe"; }};
0 0
- TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
- TopCoder SRM 645 Div2 Problem 500 - ConnectingCars (枚举)
- TopCoder SRM 661 Div2 Problem 500 - BridgeBuildingDiv2 (枚举 + 状态压缩)
- TopCoder SRM 677 Div. 2 550 - FourStrings (枚举)
- TopCoder SRM 633 Div.2 500 Jumping
- Topcoder SRM 462 DIV 2
- topcoder srm 518 div 2
- TopCoder SRM 561 Div 2
- Topcoder SRM 565 Div.2
- Topcoder SRM 628 DIV 2
- TopCoder SRM 144 DIV 2
- Topcoder srm 653 div.2 500 - RockPaperScissorsMagicEasy(DP)
- [TopCoder] SRM 586 DIV 2, 500p, 1000p, Solution
- Topcoder SRM 709 DIV 2 500pt Permatchd2 solution
- TopCoder SRM 633 Div2 Problem 500 - Jumping
- TopCoder SRM 634 Div2 Problem 500 - ShoppingSurvey
- Topcoder SRM 663 Div2 Problem 500
- Topcoder SRM 648 Div.2 - A(水), B(枚举),C(DP/构造)
- 分享DCT, DST, Walsh, Hadamard , Haar和Slant图像处理程序
- 总结-Java何时需要使用多线程
- sublime 快捷键
- 【翻译自mos文章】Oracle GoldenGate 对IBM大型机 z/OS 2.1 和DB2 v11的支持
- Java多线程ExecutorService.shutdown什么时候执行
- TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
- poj 3450 Corporate Identity 【KMP】【求公共子串】
- hdu1009
- 以创业者的姿态做一名工程师
- java synchronized详解(转载)
- 1025. PAT Ranking (25)
- Java开发环境搭建
- HDU2103Family planning
- poj 3080 Blue Jeans【KMP】【求公共子串】