Compare commits

...

12 Commits

Author SHA1 Message Date
7b20efe5f3 added algorithms 4th edirtion book for java syntqax and all 2026-04-27 22:27:59 -05:00
fcda1c6e25 comments for bob solutions 2026-04-19 00:02:15 -05:00
ee7b6b1581 utd bob competition over 2026-04-18 16:02:31 -05:00
3936b37e29 some 2026-04-18 14:37:54 -05:00
6cd3aca9a0 solved dealem out, not weight diff 2026-04-18 13:33:08 -05:00
74a593bcce added book 2026-04-18 11:47:17 -05:00
f072279dba e 2026-04-18 11:37:43 -05:00
b89de536f4 readonly fix 2026-04-18 11:33:37 -05:00
b578ed198f Minesweeper working 2026-04-17 19:50:58 -05:00
03b52c84ca battle of the brains setup 2026-04-17 17:08:37 -05:00
26614ea552 test 2026-04-17 17:06:11 -05:00
dafcadfd71 failed skewer scurvy solution but the idea is there 2026-04-16 20:16:51 -05:00
14 changed files with 572 additions and 0 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
LICENSE Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

Binary file not shown.

Binary file not shown.

View 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();
}
}

View 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;
}
}

View 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;
}
}
}
}

View 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();
}
}

View 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();
}
}

View 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);
}
}

View 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!");
}
}

View 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]++;
}
}
}
}
}

View 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();
}
}