Compare commits
16 Commits
5a05a4484e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b20efe5f3 | |||
| fcda1c6e25 | |||
| ee7b6b1581 | |||
| 3936b37e29 | |||
| 6cd3aca9a0 | |||
| 74a593bcce | |||
| f072279dba | |||
| b89de536f4 | |||
| b578ed198f | |||
| 03b52c84ca | |||
| 26614ea552 | |||
| dafcadfd71 | |||
| 205784aebe | |||
| 16832f6cea | |||
| c4e90f16e5 | |||
| 3410dd8880 |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
algorithms/.gitkeep
Normal file
0
algorithms/.gitkeep
Normal file
BIN
resources/algorithms-4th-edition.pdf
Normal file
BIN
resources/algorithms-4th-edition.pdf
Normal file
Binary file not shown.
BIN
resources/competitive-programmers-handbook.pdf
Normal file
BIN
resources/competitive-programmers-handbook.pdf
Normal file
Binary file not shown.
36
solutions/battle-of-the-brains-2026/DealEmOut.java
Normal file
36
solutions/battle-of-the-brains-2026/DealEmOut.java
Normal file
@@ -0,0 +1,36 @@
|
||||
// General imports
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
// Full solved correct solution
|
||||
public class DealEmOut {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
// Write code here
|
||||
|
||||
int a = sc.nextInt();
|
||||
int b = sc.nextInt();
|
||||
int c = sc.nextInt();
|
||||
|
||||
int cards = 0;
|
||||
int value = a + b + c;
|
||||
|
||||
if (a == 0)
|
||||
cards++;
|
||||
if (b == 0)
|
||||
cards++;
|
||||
if (c == 0)
|
||||
cards++;
|
||||
|
||||
int known = 3 - cards;
|
||||
|
||||
double adder = (416.0 - value) / (52.0 - known);
|
||||
|
||||
double returner = value + adder * cards;
|
||||
|
||||
System.out.printf("%.2f", returner);
|
||||
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
51
solutions/battle-of-the-brains-2026/DontTestMe.java
Normal file
51
solutions/battle-of-the-brains-2026/DontTestMe.java
Normal file
@@ -0,0 +1,51 @@
|
||||
// General imports
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
//Incomplete Not Working
|
||||
public class DontTestMe {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||
int N = Integer.parseInt(st.nextToken());
|
||||
int H = Integer.parseInt(st.nextToken());
|
||||
Test[] ar = new Test[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
st = new StringTokenizer(br.readLine());
|
||||
ar[i] = new Test(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),
|
||||
Double.parseDouble(st.nextToken()));
|
||||
}
|
||||
|
||||
Arrays.sort(ar, (a1, a2) -> a1.compareTo(a2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
int hours, points;
|
||||
double percent;
|
||||
double weight;
|
||||
|
||||
public Test(int h, int p, double per) {
|
||||
hours = h;
|
||||
points = p;
|
||||
percent = per;
|
||||
weight = 1 / (double) hours * points * percent;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
Test t = (Test) o;
|
||||
if (this.weight > t.weight)
|
||||
return 1;
|
||||
else if (this.weight < t.weight)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
84
solutions/battle-of-the-brains-2026/Island.java
Normal file
84
solutions/battle-of-the-brains-2026/Island.java
Normal file
@@ -0,0 +1,84 @@
|
||||
// General imports
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
//Nearly correct solution...one/two bugs passed most testcases
|
||||
public class Island {
|
||||
static int N, M;
|
||||
static int[][] grid;
|
||||
static boolean[][] visited;
|
||||
static Map<Integer, Integer> islands = new HashMap<>();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||
N = Integer.parseInt(st.nextToken());
|
||||
M = Integer.parseInt(st.nextToken());
|
||||
grid = new int[N][M];
|
||||
visited = new boolean[N][M];
|
||||
for (int i = 0; i < N; i++) {
|
||||
st = new StringTokenizer(br.readLine());
|
||||
for (int j = 0; j < M; j++) {
|
||||
int cell = Integer.parseInt(st.nextToken());
|
||||
grid[i][j] = cell;
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < M; j++) {
|
||||
if (visited[i][j])
|
||||
continue;
|
||||
if (grid[i][j] > 0) {
|
||||
islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1);
|
||||
search(grid[i][j], i, j);
|
||||
} else {
|
||||
visited[i][j] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (islands.size() == 0) {
|
||||
System.out.println(0);
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<Integer, Integer> e : islands.entrySet()) {
|
||||
int terrainNumber = e.getKey();
|
||||
int islandNum = e.getValue();
|
||||
System.out.printf("%d %d%n", terrainNumber, islandNum);
|
||||
}
|
||||
}
|
||||
|
||||
static void search(int val, int i, int j) {
|
||||
if (visited[i][j])
|
||||
return;
|
||||
visited[i][j] = true;
|
||||
for (int dir = 0; dir < 4; dir++) {
|
||||
switch (dir) {
|
||||
case 0:
|
||||
if (j + 1 < M && grid[i][j + 1] == val) {
|
||||
search(val, i, j + 1);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (i + 1 < N && grid[i + 1][j] == val) {
|
||||
search(val, i + 1, j);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (j - 1 >= 0 && grid[i][j - 1] == val) {
|
||||
search(val, i, j - 1);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (i - 1 >= 0 && grid[i - 1][j] == val) {
|
||||
search(val, i - 1, j);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
solutions/battle-of-the-brains-2026/MaximumAura.java
Normal file
61
solutions/battle-of-the-brains-2026/MaximumAura.java
Normal file
@@ -0,0 +1,61 @@
|
||||
// General imports
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
//Correct solution with too much time complexity O(n*n) fails almost every test case to time
|
||||
public class MaximumAura {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
long t = System.nanoTime();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
PrintWriter out = new PrintWriter(System.out);
|
||||
|
||||
// Write code here
|
||||
|
||||
int a = Integer.parseInt(br.readLine());
|
||||
int[] input = new int[a];
|
||||
int[] left = new int[a];
|
||||
int[] right = new int[a];
|
||||
left[0] = 1;
|
||||
right[a - 1] = 1;
|
||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||
for (int i = 0; i < a; i++) {
|
||||
input[i] = Integer.parseInt(st.nextToken());
|
||||
}
|
||||
|
||||
for (int i = 1; i < input.length; i++) {
|
||||
int max = 0;
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (input[j] < input[i]) {
|
||||
max = Math.max(max, left[j]);
|
||||
}
|
||||
}
|
||||
left[i] = max + 1;
|
||||
}
|
||||
|
||||
for (int i = a - 2; i >= 0; i--) {
|
||||
right[i] = 1;
|
||||
int max = 0;
|
||||
for (int j = a - 1; j > i; j--) {
|
||||
if (input[j] < input[i]) {
|
||||
max = Math.max(max, right[j]);
|
||||
}
|
||||
}
|
||||
right[i] += max;
|
||||
}
|
||||
PriorityQueue<Integer> p = new PriorityQueue<>();
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
out.print((left[i] + right[i] - 1) + " ");
|
||||
}
|
||||
|
||||
br.close();
|
||||
out.flush();
|
||||
|
||||
}
|
||||
}
|
||||
17
solutions/battle-of-the-brains-2026/Solution.java
Normal file
17
solutions/battle-of-the-brains-2026/Solution.java
Normal file
@@ -0,0 +1,17 @@
|
||||
// General imports
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Solution {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
// Write code here
|
||||
|
||||
int a = sc.nextInt();
|
||||
System.out.println(a);
|
||||
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
|
||||
49
solutions/battle-of-the-brains-2026/WeightedDifference.java
Normal file
49
solutions/battle-of-the-brains-2026/WeightedDifference.java
Normal file
@@ -0,0 +1,49 @@
|
||||
// General imports
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
// Working but O(n*n) --> 50% of test cases fail on time complexity
|
||||
public class WeightedDifference {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
double t = System.currentTimeMillis();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
// Write code here
|
||||
|
||||
int a = Integer.parseInt(br.readLine());
|
||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||
int[] ar = new int[a];
|
||||
for (int i = 0; i < a; i++) {
|
||||
ar[i] = Integer.parseInt(st.nextToken());
|
||||
}
|
||||
|
||||
long max = Long.MIN_VALUE;
|
||||
int left = 0;
|
||||
int right = ar.length - 1;
|
||||
int gap = right - left;
|
||||
int prevGap = 0;
|
||||
while (gap > 0) {
|
||||
int diff = ar[right] - ar[left] - (right - left);
|
||||
max = diff > max ? diff : max;
|
||||
if (gap == prevGap && right < ar.length - 1) {
|
||||
left++;
|
||||
right++;
|
||||
} else {
|
||||
gap--;
|
||||
prevGap = gap;
|
||||
left = 0;
|
||||
right = gap;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(max);
|
||||
System.out.println(System.currentTimeMillis() - t);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
solutions/leetcode/Problem657.java
Normal file
42
solutions/leetcode/Problem657.java
Normal file
@@ -0,0 +1,42 @@
|
||||
// General imports
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
|
||||
public class Problem657 {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
// Write code here
|
||||
|
||||
String s = sc.nextLine();
|
||||
|
||||
System.out.println(judgeCircle(s));
|
||||
|
||||
sc.close();
|
||||
|
||||
}
|
||||
|
||||
public static boolean judgeCircle(String moves) {
|
||||
int verticalPos = 0;
|
||||
int horizontalPos = 0;
|
||||
|
||||
for (char c : moves.toCharArray()) {
|
||||
if (c == 'R') {
|
||||
horizontalPos++;
|
||||
} else if (c == 'L') {
|
||||
horizontalPos--;
|
||||
}
|
||||
|
||||
if (c == 'U') {
|
||||
verticalPos++;
|
||||
} else if (c == 'D') {
|
||||
verticalPos--;
|
||||
}
|
||||
}
|
||||
|
||||
return (verticalPos == 0 && horizontalPos == 0);
|
||||
}
|
||||
}
|
||||
11
solutions/practice/HelloWorld.java
Normal file
11
solutions/practice/HelloWorld.java
Normal file
@@ -0,0 +1,11 @@
|
||||
// General imports
|
||||
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
import java.util.*;
|
||||
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
120
solutions/practice/Minesweeper.java
Normal file
120
solutions/practice/Minesweeper.java
Normal file
@@ -0,0 +1,120 @@
|
||||
// General imports
|
||||
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Minesweeper {
|
||||
static char[][] input;
|
||||
static int poss = 0;
|
||||
static int[][] safe;
|
||||
static int r;
|
||||
static int c;
|
||||
static int b;
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
// Write code here
|
||||
|
||||
r = sc.nextInt();
|
||||
c = sc.nextInt();
|
||||
b = sc.nextInt();
|
||||
|
||||
input = new char[r][c];
|
||||
safe = new int[r][c];
|
||||
|
||||
for (int i = 0; i < r; i++) {
|
||||
String s = sc.next();
|
||||
for (int j = 0; j < c; j++) {
|
||||
input[i][j] = s.charAt(j);
|
||||
safe[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sc.close();
|
||||
|
||||
solve(0, input, 0);
|
||||
if (poss == 0) {
|
||||
System.out.println("0.000");
|
||||
} else {
|
||||
double maxProb = (double) safe[0][0] / (double) poss;
|
||||
|
||||
for (int i = 0; i < safe.length; i++) {
|
||||
for (int j = 0; j < safe[i].length; j++) {
|
||||
maxProb = Math.max(maxProb, (double) (safe[i][j]) / (double) poss);
|
||||
}
|
||||
}
|
||||
|
||||
String s = String.format("%.3f", maxProb);
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void solve(int index, char[][] grid, int bombs) {
|
||||
if (index >= r * c) {
|
||||
if (bombs == b && isValid(grid)) {
|
||||
addPoss(grid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int row = (int) Math.floor(index / c);
|
||||
int col = (index % c);
|
||||
|
||||
if (bombs > b)
|
||||
return;
|
||||
|
||||
char[][] gridCopy = new char[r][c];
|
||||
|
||||
for (int i = 0; i < r; i++) {
|
||||
for (int j = 0; j < c; j++) {
|
||||
gridCopy[i][j] = grid[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
if (gridCopy[row][col] == '#') {
|
||||
gridCopy[row][col] = 'b';
|
||||
solve(index + 1, gridCopy, bombs + 1);
|
||||
gridCopy[row][col] = '#';
|
||||
solve(index + 1, gridCopy, bombs);
|
||||
} else {
|
||||
solve(index + 1, gridCopy, bombs);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public static boolean isValid(char[][] grid) {
|
||||
for (int i = 0; i < grid.length; i++) {
|
||||
for (int j = 0; j < grid[i].length; j++) {
|
||||
if (Character.isDigit(grid[i][j])) {
|
||||
int total = grid[i][j] - '0';
|
||||
int cand = 0;
|
||||
for (int l = -1; l <= 1; l++) {
|
||||
for (int m = -1; m <= 1; m++) {
|
||||
if (i + l < grid.length && i + l >= 0 && j + m < grid[i].length && j + m >= 0) {
|
||||
if (grid[i + l][j + m] == 'b')
|
||||
cand++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cand != total)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void addPoss(char[][] grid) {
|
||||
poss++;
|
||||
for (int i = 0; i < grid.length; i++) {
|
||||
for (int j = 0; j < grid[i].length; j++) {
|
||||
if (grid[i][j] == '#') {
|
||||
safe[i][j]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
115
solutions/practice/MinesweeperMacaw.java
Normal file
115
solutions/practice/MinesweeperMacaw.java
Normal file
@@ -0,0 +1,115 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class MinesweeperMacaw {
|
||||
public static char[][] grid;
|
||||
public static char[][] modGrid;
|
||||
public static int unknowns = 0;
|
||||
public static boolean solved = false;
|
||||
public static HashMap<Integer, ArrayList<Integer>> unknownLocations = new HashMap<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int size = sc.nextInt();
|
||||
int macaws = sc.nextInt();
|
||||
grid = new char[size][size];
|
||||
|
||||
for (int i = 0; i < grid.length; i++) {
|
||||
|
||||
for (int j = 0; j < grid.length; j++) {
|
||||
grid[i][j] = sc.next().charAt(0);
|
||||
if (grid[i][j] == '.') {
|
||||
ArrayList<Integer> l = new ArrayList<>();
|
||||
l.add(i);
|
||||
l.add(j);
|
||||
unknownLocations.put(unknowns, l);
|
||||
unknowns++;
|
||||
}
|
||||
}
|
||||
}
|
||||
modGrid = new char[size][size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
modGrid[i] = grid[i].clone();
|
||||
}
|
||||
|
||||
if (unknowns != 0) {
|
||||
placeMacaws(0, macaws);
|
||||
}
|
||||
|
||||
printGrid(grid);
|
||||
|
||||
sc.close();
|
||||
|
||||
}
|
||||
|
||||
public static void placeMacaws(int index, int macawsLeft) {
|
||||
if (macawsLeft == 0) {
|
||||
if (valid(modGrid)) {
|
||||
for (int i = 0; i < modGrid.length; i++) {
|
||||
grid[i] = modGrid[i].clone();
|
||||
}
|
||||
solved = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (solved)
|
||||
return;
|
||||
|
||||
if (index == unknowns) {
|
||||
return;
|
||||
}
|
||||
|
||||
int a = unknownLocations.get(index).get(0);
|
||||
int b = unknownLocations.get(index).get(1);
|
||||
|
||||
modGrid[a][b] = 'M';
|
||||
placeMacaws(index + 1, macawsLeft - 1);
|
||||
|
||||
modGrid[a][b] = '.';
|
||||
placeMacaws(index + 1, macawsLeft);
|
||||
|
||||
}
|
||||
|
||||
public static boolean valid(char[][] input) {
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
for (int j = 0; j < input[i].length; j++) {
|
||||
char c = input[i][j];
|
||||
if (Character.isDigit(c)) {
|
||||
int val = c - '0';
|
||||
int num = 0;
|
||||
|
||||
for (int m = -1; m < 2; m++) {
|
||||
for (int n = -1; n < 2; n++) {
|
||||
if (i + m >= 0 && i + m < input.length && j + n >= 0 && j + n < input[0].length) {
|
||||
if (input[i + m][j + n] == 'M') {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (num != val) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void printGrid(char[][] input) {
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
String out = "";
|
||||
for (int j = 0; j < input[i].length - 1; j++) {
|
||||
out = out + input[i][j];
|
||||
out += " ";
|
||||
}
|
||||
out += input[i][input[i].length - 1];
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
143
solutions/practice/SkewerScurvyEasy.java
Normal file
143
solutions/practice/SkewerScurvyEasy.java
Normal file
@@ -0,0 +1,143 @@
|
||||
// General imports
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
|
||||
public class SkewerScurvyEasy {
|
||||
static char[][] input;
|
||||
static int[][] ids;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
int a = sc.nextInt();
|
||||
|
||||
for (int i = 0; i < a; i++) {
|
||||
int count = 1;
|
||||
int h = sc.nextInt();
|
||||
int w = sc.nextInt();
|
||||
input = new char[h][w];
|
||||
ids = new int[h][w];
|
||||
for (int k = 0; k < input.length; k++) {
|
||||
String s = sc.next();
|
||||
for (int j = 0; j < input[0].length; j++) {
|
||||
input[k][j] = s.charAt(j);
|
||||
ids[k][j] = count;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
boolean hitPillar = false;
|
||||
|
||||
ArrayList<Integer> safeNorth = new ArrayList<>();
|
||||
|
||||
for (int j = 0; j < w; j++) {
|
||||
hitPillar = false;
|
||||
for (int k = 0; k < h; k++) {
|
||||
if (hitPillar && input[k][j] != '#') {
|
||||
safeNorth.add(ids[k][j]);
|
||||
}
|
||||
|
||||
if (input[k][j] == '#') {
|
||||
hitPillar = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String out = "Testcase " + i + " NORTH:";
|
||||
Collections.sort(safeNorth);
|
||||
for (int n = 0; n < safeNorth.size(); n++) {
|
||||
out = out + " " + safeNorth.get(n);
|
||||
}
|
||||
|
||||
System.out.println(out);
|
||||
|
||||
hitPillar = false;
|
||||
|
||||
ArrayList<Integer> safeEast = new ArrayList<>();
|
||||
|
||||
for (int k = 0; k < h; k++) {
|
||||
hitPillar = false;
|
||||
|
||||
for (int j = w - 1; j >= 0; j--) {
|
||||
if (hitPillar && input[k][j] != '#') {
|
||||
safeEast.add(ids[k][j]);
|
||||
}
|
||||
|
||||
if (input[k][j] == '#') {
|
||||
hitPillar = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
out = "Testcase " + i + " EAST :";
|
||||
Collections.sort(safeEast);
|
||||
for (int n = 0; n < safeEast.size(); n++) {
|
||||
out = out + " " + safeEast.get(n);
|
||||
}
|
||||
|
||||
System.out.println(out);
|
||||
|
||||
hitPillar = false;
|
||||
|
||||
ArrayList<Integer> safeSouth = new ArrayList<>();
|
||||
|
||||
for (int j = 0; j < w; j++) {
|
||||
hitPillar = false;
|
||||
|
||||
for (int k = h - 1; k >= 0; k--) {
|
||||
if (hitPillar && input[k][j] != '#') {
|
||||
safeSouth.add(ids[k][j]);
|
||||
}
|
||||
|
||||
if (input[k][j] == '#') {
|
||||
hitPillar = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
out = "Testcase " + i + " SOUTH:";
|
||||
Collections.sort(safeSouth);
|
||||
for (int n = 0; n < safeSouth.size(); n++) {
|
||||
out = out + " " + safeSouth.get(n);
|
||||
}
|
||||
|
||||
System.out.println(out);
|
||||
|
||||
hitPillar = false;
|
||||
|
||||
ArrayList<Integer> safeWest = new ArrayList<>();
|
||||
|
||||
for (int k = 0; k < h; k++) {
|
||||
hitPillar = false;
|
||||
|
||||
for (int j = 0; j < w; j++) {
|
||||
if (hitPillar && input[k][j] != '#') {
|
||||
safeWest.add(ids[k][j]);
|
||||
}
|
||||
|
||||
if (input[k][j] == '#') {
|
||||
hitPillar = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
out = "Testcase " + i + " WEST :";
|
||||
Collections.sort(safeWest);
|
||||
for (int n = 0; n < safeWest.size(); n++) {
|
||||
out = out + " " + safeWest.get(n);
|
||||
}
|
||||
|
||||
System.out.println(out);
|
||||
|
||||
}
|
||||
|
||||
sc.close();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user