Mars Lander Episode 2 – lądowanie na Marsie – omówienie zadania z CodinGame

Szczegółowe omówienie zadania Mars Lander Episode 2:

Link do powyższego omówienia zadania Mars Lander Episode 2:
https://youtu.be/jp-VSdI8PJ4?t=1958

Link do treści zadania Mars Lander Episode 2:
https://www.codingame.com/ide/puzzle/mars-lander-episode-2


Zadanie Mars Lander Episode 2 jest fantastycznym zadaniem gdzie musimy wymyślić własną strategię lądowania – gdzie jest wiele podejść.
Zadanie Mars Lander Episode 2 pochodzi z platformy CodinGame.
CodinGame to miejsce gdzie uczymy się programować bawiąc się grami.
Kodować możemy używając dowolnego języka programowania.
Jednocześnie CodinGame tworzy dla nas gotowe CV które jest dostępne dla potencjalnych pracodawców:
https://youtu.be/yUh6XdlGm14?t=3702


Niżej znajdziesz
* kody poszczególnych faz tworzenia rozwiązania.
* linki do omówienia danego rozwiązania
Najpierw pokazane jest optymalne rozwiązanie.

====
Kod C++ programu Mars Lander Episode 2, który jest omówiony w powyższym filmie i który otrzymuje 100%

#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.
**/
int main()
{
int previous_y, previous_x;
int central_x, central_y;
int land_start_x, land_end_x;
int land_length;
int surfaceN; // the number of points used to draw the surface of Mars.
cin >> surfaceN; cin.ignore();
for (int i = 0; i < surfaceN; i++) {
int landX; // X coordinate of a surface point. (0 to 6999)
int landY; // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
//    cerr << landX << " " << landY << endl;
cin >> landX >> landY; cin.ignore();
if (landY == previous_y) {
//if land area found - we remember it
land_start_x = previous_x;
land_end_x = landX;
central_x = (land_start_x+land_end_x)/2;
central_y = landY;
}
previous_y = landY;
previous_x = landX;
}
//we limit ladn area for 5%
land_length = land_end_x - land_start_x;
land_start_x = land_start_x + land_length/20;
land_end_x = land_end_x - land_length/20;
//    cerr << land_start_x << " " << land_end_x << endl;
//    cerr << central_x << " " << central_y << endl;
// game loop
while (1) {
int X;
int Y;
int hSpeed; // the horizontal speed (in m/s), can be negative.
int vSpeed; // the vertical speed (in m/s), can be negative.
int fuel; // the quantity of remaining fuel in liters.
int rotate; // the rotation angle in degrees (-90 to 90).
int power; // the thrust power (0 to 4).
cin >> X >> Y >> hSpeed >> vSpeed >> fuel >> rotate >> power; cin.ignore();
//By default we have max power of rocket
power = 4;
//if we are left of land
if (X < land_start_x)
if (hSpeed <= 60)
//if horizontal speed too SLOW -> we speed up by rotating 30 degree from vertical
rotate = -30;
else if (hSpeed >= 70)
//if horizontal speed too FAST -> we speed up by rotating 30 degree from vertical but in opposite direction
rotate = 30;
else
//if horizontal speed between 60 and 70 m/s we are in vertical position
rotate = 0;
//if we are right of land -> we do he ssame
if (X > land_end_x)
if (hSpeed >= -60)
rotate = 30;
else if (hSpeed <= -70)
rotate = -30;
else
rotate = 0;
//if we are at the land area
if ( (X > land_start_x) && (X < land_end_x) )
//we want that horizontal speed is between -5 and 5 m/s
if (hSpeed < -5)
rotate = -45;
else if (hSpeed > 5)
rotate = 45;
else {
//if speed is ok, we are in vertical position
rotate = 0;
//if speed is too FAST (over 30m/s) we give max power up to slow down
if (vSpeed < -30)
power = 4;
else
//if speed is ok (less than 30m/s) we give 0 power to speed down to ground
power = 0;
}     
// rotate power. rotate is the desired rotation angle. power is the desired thrust power.
cout << rotate << " " << power << endl;
}
}
Kod C++ programu Mars Lander Episode 2, który jest omówiony w powyższym filmie i który otrzymuje 100%

 

 

Nie dodano jeszcze komentarza, rozpocznij dyskusję pierwszy.

Dodaj komentarz