Problem Link : http://www.codechef.com/problems/RESN04
Solution :
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author XCoder
*/
class StoneGame {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
public static int readIntLine() throws IOException {
return Integer.parseInt(br.readLine());
}
public static void main(String[] args) throws IOException {
int test = readIntLine();
while (test-- > 0) {
int noofpiles = readIntLine();
int iarr[] = new int[noofpiles];
String str = br.readLine();
String strarr[] = str.split(" ");
for (int i = 0; i < strarr.length; i++) {
iarr[i] = Integer.parseInt(strarr[i]);
}
int winner = 0;
for (int i = 0; i < iarr.length; i++) {
if (iarr[i] >= i + 1) {
iarr[i] -= (i + 1);
winner++;
i--;
}
}
if (winner % 2 == 0) {
pw.println("BOB");
} else {
pw.println("ALICE");
}
}
pw.flush();
pw.close();
}
}
No comments:
Post a Comment