Advertisement
abhisekp

CodinGame - Mars Lander - Level 1

Jan 31st, 2015
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1.         int N = in.nextInt(); // the number of points used to draw the surface of Mars.
  2.        
  3.         int prevLAND_X = -1;
  4.         int prevLAND_Y = -1;
  5.         int startX = -1;
  6.         int endX = -1;
  7.         int startY = -1;
  8.         int endY = -1;
  9.         for (int i = 0; i < N; i++) {
  10.             int LAND_X = in.nextInt(); // X coordinate of a surface point. (0 to 6999)
  11.             int LAND_Y = in.nextInt(); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
  12.  
  13.             if(LAND_Y == prevLAND_Y && (LAND_X - prevLAND_X) >= 1000) { // 1000 gap
  14.                 startX = prevLAND_X;
  15.                 endX = LAND_X;
  16.                
  17.                 startY = prevLAND_Y;
  18.                 endY = LAND_Y;
  19.             }
  20.            
  21.             prevLAND_X = LAND_X;
  22.             prevLAND_Y = LAND_Y;
  23.         }
  24.  
  25.         int rot = 0;
  26.         int pow = 3;
  27.  
  28.         // game loop
  29.         while (true) {
  30.             final int X = in.nextInt(); // x coordinate of mars lander
  31.             final int Y = in.nextInt(); // y coordinate of mars lander
  32.             final int HS = in.nextInt(); // the horizontal speed (in m/s), can be negative.
  33.             final int VS = in.nextInt(); // the vertical speed (in m/s), can be negative.
  34.             final int F = in.nextInt(); // the quantity of remaining fuel in liters.
  35.             final int R = in.nextInt(); // the rotation angle in degrees (-90 to 90).
  36.             final int P = in.nextInt(); // the thrust power (0 to 4).
  37.  
  38.             // define rotation and power
  39.             if(X >= startX && X <= endX) {
  40.                 rot = 0;
  41.             }
  42.            
  43.             // define power
  44.             if(VS < -30 && P < 4) {
  45.                 System.err.println("Power increased.");
  46.                 pow = P + 1;
  47.             }
  48.            
  49.             if(VS > -10 && P > 1) {
  50.                 System.err.println("Power decreased.");
  51.                 pow = P - 1;
  52.             }
  53.                        
  54.             System.out.println(rot + " " + pow); // R P. R is the desired rotation angle. P is the desired thrust power.
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement