모름

문제 요약

 

Mars Lander 문제는 조건 활용 문제입니다.

 

 

위와 같은 상황에서 조건식을 잘 짜서 우주선을 바닥에 잘 착륙시키는게 목표입니다. ep1에선 문제의 이해를 위해 우주선은 수직으로만 떨어집니다.

 

 

 


 

 

 

입력과 출력

 

입력 :

 

주어진 입력 값(조건)은 위와 같습니다. X(우주선 가로위치), Y(우주선 세로위치), hSpeed(좌우로 이동하는 스피드), vSpeed(수직으로 떨어지는 속도), fuel(연료), rotate(우주선의 회전값), power(우주선 출력)입니다. 이 변수들을 활용하여 조건식을 짜고 제한사항에 맞추어 우주선을 바닥에 착륙시켜야합니다.

 

출력 :

 

저희는 단지 2개의 값만 조정할 수 있습니다. 바로 rotate와 power입니다. 값 입력은 Console.WriteLine()으로 할 수 있습니다. 

 

 

 


 

 

 

제한

 

우주선 조종에는 제약사항이 있습니다.

 

위와 같은 제약사항을 조건을 설정하여 착륙 시도 중에 지키도록 코딩해야합니다.

 

 

 


 

 

 

코드 구현

 

if(vSpeed < -38)
{
    Console.WriteLine("0 4");
}
else
{
    Console.WriteLine("0 1");
}

 

이번 문제에선 우주선은 그저 수직으로 떨어집니다. 때문에 수직스피드가 -40보다 더 빨라지지 않게만 조정해주면 됩니다. 때문에 떨어지는 속도가 38보다 더 빨라지면 출력을 최대(4)로 해주어서 38보다 느리게 해줍니다. 그리고 연료 및 속도를 내기 위해서 출력(1)로 낮춥니다. 이를 반복하면 우주선은 속도를 35~40사이를 왔다갔다 하는데, 바닥까지 무사히 착륙하게 됩니다.

 

 


 

 

 

출력 화면

 

...출력

 

무사히 착륙했습니다. 쉬운 내용이라 짬내서 해봤습니다. 문제를 직접 풀어보시길 바랍니다.

 

 

보시면 VSpeed를 40을 넘기지 않게 계속 유지해주고 있습니다. 마지막 착륙지점에서 40을 넘기지 않았기 때문에 성공했다는 표시가 나옵니다. 화성착륙 성공!

 

 


 

 

 

코드 전문

 

...코드 전문

더보기
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/
class Player
{
    static void Main(string[] args)
    {
        string[] inputs;
        int surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars.
        for (int i = 0; i < surfaceN; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999)
            int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
        }

        // game loop
        while (true)
        {
            inputs = Console.ReadLine().Split(' ');
            int X = int.Parse(inputs[0]);
            int Y = int.Parse(inputs[1]);
            int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative.
            int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative.
            int fuel = int.Parse(inputs[4]); // the quantity of remaining fuel in liters.
            int rotate = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90).
            int power = int.Parse(inputs[6]); // the thrust power (0 to 4).

            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine("Debug messages...");
            if(vSpeed < -38)
            {
                Console.WriteLine("0 4");
            }
            else
            {
                Console.WriteLine("0 1");
            }
            // 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4).
        }
    }
}