Re: [闲聊] 每日leetcode

楼主: smart0eddie (smart0eddie)   2024-07-13 11:00:50
2024-07-13
2751. Robot Collisions
There are n 1-indexed robots, each having a position on a line, health, and
movement direction.
You are given 0-indexed integer arrays positions, healths, and a string
directions (directions[i] is either 'L' for left or 'R' for right). All
integers in positions are unique.
All robots start moving on the line simultaneously at the same speed in their
given directions. If two robots ever share the same position while moving,
they will collide.
If two robots collide, the robot with lower health is removed from the line,
and the health of the other robot decreases by one. The surviving robot
continues in the same direction it was going. If both robots have the same
health, they are both removed from the line.
Your task is to determine the health of the robots that survive the
collisions, in the same order that the robots were given, i.e. final heath of
robot 1 (if survived), final health of robot 2 (if survived), and so on. If
there are no survivors, return an empty array.
Return an array containing the health of the remaining robots (in the order
they were given in the input), after no further collisions can occur.
Note: The positions may be unsorted.
继续抄解答.jpg
泥板只剩我写不出H了
题目要看哪些会机器人会相撞
要先把往左跟往右的分开
然后往右的从位置最靠右边的开始
一路往右撞过去 撞到自己死掉或是右边没有往左的障碍物
最后看还有哪些残血就是答案
所以会需要先对位置做排序
同时还要记录生命值
需要自定义排序比大小的function
https://stackoverflow.com/questions/1577475/
要再难一点应该就是不等速
甚至是四方向
不过这样我不知道除了一步一步跑模拟还能怎么办
作者: CanIndulgeMe (CIM)   2024-07-13 11:08:00
技术大神

Links booklink

Contact Us: admin [ a t ] ucptt.com