In this puzzle, the aim is to destroy the moutains below your ship, which is moving space invader style, before colliding with them. The idea is to perform a linear search and shoot the highest moutain each time an ammo is available.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int oldY = -1;
int target = -1;
int x, y, max, h;
for (;;) {
scanf("%d%d", &x, &y);
/* One new ammo is available each time the height change
The highest moutain is the new target */
if (y != oldY) {
oldY = y;
max = 0;
for (int i = 0; i < 8; i++) {
scanf("%d", &h);
if (h > max) {
target = i;
max = h;
}
}
}
// If height hasn't change, flushes stdin
else
for (int i = 0; i < 8; i++)
scanf("%d", &h);
printf(x == target ? "FIRE\n" : "HOLD\n");
}
return EXIT_SUCCESS;
}
import java.util.*;
import java.math.*;
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int[] surfaceX = new int[N];
int[] surfaceY = new int[N];
for (int i = 0; i < N; i++) {
surfaceX[i] = in.nextInt();
surfaceY[i] = in.nextInt();
}
while (true) {
int X = in.nextInt();
int Y = in.nextInt();
int dX = in.nextInt();
int dY = in.nextInt();
in.nextInt(); in.nextInt(); in.nextInt();
// Finds landing altitude by Looking for 2 consecutive points w/ same Y
int groundY = -1;
for (int i = 0; (i < N && groundY == -1); i++)
if (surfaceX[i] <= X && X <= surfaceX[i+1])
groundY = surfaceY[i];
/* Finds out if it is safe to start braking only next turn, by
simulating it and analyzing vertical speed at landing
If it is safe, waits, else starts braking*/
double vdY = dY - 8.555;
double vY = Y - 36.665 + 5*dY;
long t = Math.round((-40-vdY)/0.289);
if (vY + t*(vdY+0.289*(1+t)/2) > groundY)
System.out.println("0 0");
else
System.out.println("0 4");
}
}
}
import math
N = int(input())
surfaceX, surfaceY = [], []
for i in range(N):
landX, landY = [int(j) for j in input().split()]
surfaceX.append(landX)
surfaceY.append(landY)
while 1:
X, Y, dX, dY, fuel, rotate, power = [int(i) for i in input().split()]
# Finds landing altitude by Looking for 2 consecutive points w/ same Y
groundY, i = -1, 0
while (i < N) and (groundY == -1):
if (surfaceX[i] <= X) and (X <= surfaceX[i+1]):
groundY = surfaceY[i]
i+=1
# Finds out if it is safe to start braking only next turn, by
# simulating it and analyzing vertical speed at landing
# If it is safe, waits, else starts braking
vdY , vY = dY-8.555, Y-36.665+5*dY;
t = math.ceil((-40-vdY)/0.289);
if (vY + t*(vdY+0.289*(1+t)/2) > groundY):
print(0, 0)
else:
print(0, 4)