CodinGame: Power of Thor 反思

本文回顾了在CodinGame的Power of Thor挑战中,通过逐步优化策略帮助Thor到达能量之光的过程。从最初的简单移动策略,到尝试枚举所有可能的方向,再到引入分类思想分析lightX和initialTX的关系,最终实现通关。文章强调了Debug技巧和选择结构在解决问题中的重要性。
摘要由CSDN通过智能技术生成

Power of Thor 雷神托尔的能量

主界面

The Goal

Your program must allow Thor to reach the light of power.
//你的程序必须能让Thor到达能量之光

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”.
//Thor在一个40*18的地图上移动。注意左上方建立的坐标系,左上角为(0,0)和右下角(39,17),Thor的位置超出界限(X<0,X>39,Y<0,Y>17)都算输
//coordinate: 坐标
关卡1

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. //Thor开始的位置
·the variable initialTY: the starting Y position of Thor.

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 or NW
东南西北

原程序

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 * ---
 * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
 * 提示:当Thor没有按照你预想的方式来移动时
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值