Skip to content

Instantly share code, notes, and snippets.

@vchatela
Created February 11, 2016 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vchatela/57f8d61e0e1578ee070d to your computer and use it in GitHub Desktop.
Save vchatela/57f8d61e0e1578ee070d to your computer and use it in GitHub Desktop.
Codingame : Heat Detector Java
import java.util.*;
import java.io.*;
import java.math.*;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Player {
private static final String UP = "U";
private static final String DOWN = "D";
private static final String LEFT = "L";
private static final String RIGHT = "R";
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int W = in.nextInt(); // width of the building.
int H = in.nextInt(); // height of the building.
int N = in.nextInt(); // maximum number of turns before game over.
int X0 = in.nextInt();
int Y0 = in.nextInt();
int xl = 0;
int yt = 0;
int xr = W;
int yb = H;
// game loop
while (true) {
String BOMBDIR = in.next(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
if (BOMBDIR.contains("L")) {
xr = X0;
}
if (BOMBDIR.contains("R")) {
xl = X0 + 1;
}
if (BOMBDIR.contains("U")) {
yb = Y0;
}
if (BOMBDIR.contains("D")) {
yt = Y0 + 1;
}
X0 = (xl + xr) / 2;
Y0 = (yt + yb) / 2;
System.out.println(X0 + " " + Y0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment