Path to victory

无论身处何种境遇,总有两条道路摆在眼前:一条通往成功,另一条则通向失败。关键在于我们如何选择并采取行动。博客鼓励读者认识到希望始终存在,只要一步步前进,就能达到心中的目的地。
 

转载自:http://greatday.com/motivate/070508.html

Tuesday, May 8, 2007

Path to victory

From this moment, there is a path that leads toward victory and another path that leads toward defeat. Which path is your awareness focused upon?

Each pathway is equally valid, equally realistic, and equally accessible. Which path have you chosen to follow?

The particular circumstances of this moment don't really matter that much. What matters is what you decide to do with what you have right now.

Know, without a doubt, that there is a very real path that goes from where you are now to where you would most like to be. Know it and you will surely see it.

Always, there is hope, for always you can take a step forward. Step by step, you can work your way to any place you choose.

Get yourself on the path that leads to victory, to accomplishment and fulfillment of your most deeply held purposes. That path is surely here right now, ready for you to take the next step.

-- Ralph Marston

 
Your program must allow Thor to reach the light of power. Rules Thor moves on a map which is 40 wide by 18 high. Note that the coordinates (X and Y) start at the top left! This means the most top left cell has the coordinates "X=0,Y=0" and the most bottom right one has the coordinates "X=39,Y=17". Once the program starts you are given: the variable lightX: the X position of the light of power that Thor must reach. the variable lightY: the Y position of the light of power that Thor must reach. the variable initialTX: the starting X position of Thor. the variable initialTY: the starting Y position of Thor. At the end of the game turn, you must output the direction in which you want Thor to go among: N (North) NE (North-East) E (East) SE (South-East) S (South) SW (South-West) W (West) NW (North-West) Each movement makes Thor move by 1 cell in the chosen direction. Victory Conditions You win when Thor reaches the light of power Lose Conditions Thor moves outside the map Initial phase Thor starts on the map at position (3, 6). The light is at position (3, 8). Round 1 Action S: Thor moves towards south. New position is (3, 7). Round 2 Action S: Thor moves towards south. New position is (3, 8). Note Do not forget to execute the tests from the "Test cases" panel. Beware: the tests given and the validators used to compute the score are slightly different in order to avoid hard coded solutions. Game Input The program must first read the initialization data from the standard input, then, in an infinite loop, provides on the standard output the instructions to move Thor. Initialization input Line 1: 4 integers lightX lightY initialTX initialTY. (lightX, lightY) indicates the position of the light. (initialTX, initialTY) indicates the initial position of Thor. Input for a game round Line 1: the number of remaining moves for Thor to reach the light of power: remainingTurns. You can ignore this data but you must read it. Output for a game round A single line providing the move to be made: N NE E SE S SW W ou NW Constraints 0 ≤ lightX < 40 0 ≤ lightY < 18 0 ≤ initialTX < 40 0 ≤ initialTY < 18 Response time for a game round ≤ 100ms
08-13
In a programming game scenario where Thor must move towards the light of power in a grid-based environment, the solution involves calculating the direction of movement based on the relative positions of Thor and the light of power. The grid is typically represented with coordinates, and movement is allowed in the four cardinal directions (north, south, east, west) as well as the four diagonal directions (northeast, northwest, southeast, southwest). ### Solution Overview The solution can be implemented by comparing the x and y coordinates of Thor's current position with the target position (light of power). Depending on whether Thor's x-coordinate is less than, greater than, or equal to the target's x-coordinate, and similarly for the y-coordinate, the direction of movement can be determined. Here is a step-by-step breakdown of the logic: 1. **Input Handling**: Read the initial input values for Thor's starting position and the light of power's position. 2. **Direction Calculation**: Based on the comparison of Thor's and the light's coordinates, determine the direction in which Thor should move. 3. **Output the Direction**: Print the calculated direction for each move. ### Example Code The following is a Python implementation of the solution: ```python # Read input values light_x, light_y, thor_x, thor_y = map(int, input().split()) # Calculate the difference in x and y coordinates delta_x = light_x - thor_x delta_y = light_y - thor_y # Determine the direction based on the differences direction_x = "" if delta_x > 0: direction_x = "E" elif delta_x < 0: direction_x = "W" direction_y = "" if delta_y > 0: direction_y = "S" elif delta_y < 0: direction_y = "N" # Combine the directions for the final move print(direction_y + direction_x) ``` ### Explanation - **Input Handling**: The input values are read using `input().split()` and converted to integers. These values represent the coordinates of the light of power and Thor's starting position. - **Delta Calculation**: The differences in the x and y coordinates (`delta_x` and `delta_y`) are calculated to determine the direction of movement. - **Direction Determination**: - If `delta_x` is positive, Thor needs to move east (`E`); if negative, west (`W`). - If `delta_y` is positive, Thor needs to move south (`S`); if negative, north (`N`). - **Output**: The directions for the x and y axes are combined and printed as the final move for Thor. This approach ensures that Thor moves in the shortest path possible towards the light of power, considering the grid-based environment. The code can be adapted to handle multiple steps by updating Thor's position iteratively until the light of power is reached. ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值