comments for bob solutions

This commit is contained in:
2026-04-19 00:02:15 -05:00
parent ee7b6b1581
commit fcda1c6e25
5 changed files with 30 additions and 26 deletions

View File

@@ -2,6 +2,7 @@
import java.util.Scanner;
// Full solved correct solution
public class DealEmOut {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

View File

@@ -6,8 +6,9 @@ import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class DontTestMe {
public static void main(String[] args) throws IOException{
//Incomplete Not Working
public class DontTestMe {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
@@ -15,38 +16,36 @@ public class DontTestMe {
int N = Integer.parseInt(st.nextToken());
int H = Integer.parseInt(st.nextToken());
Test[] ar = new Test[N];
for (int i =0; i < N; i++){
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()));
ar[i] = new Test(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),
Double.parseDouble(st.nextToken()));
}
Arrays.sort(ar, (a1,a2) -> a1.compareTo(a2));
Arrays.sort(ar, (a1, a2) -> a1.compareTo(a2));
}
}
class Test{
int hours,points;
class Test {
int hours, points;
double percent;
double weight;
public Test (int h, int p, double per){
public Test(int h, int p, double per) {
hours = h;
points = p;
percent = per;
weight = 1/(double) hours * points * percent;
weight = 1 / (double) hours * points * percent;
}
public int compareTo(Object o){
public int compareTo(Object o) {
Test t = (Test) o;
if (this.weight > t.weight) return 1;
else if (this.weight < t.weight) return -1;
if (this.weight > t.weight)
return 1;
else if (this.weight < t.weight)
return -1;
return 0;
}
}

View File

@@ -7,11 +7,13 @@ 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());
@@ -29,7 +31,8 @@ public class Island {
br.close();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (visited[i][j]) continue;
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);
@@ -50,10 +53,11 @@ public class Island {
}
static void search(int val, int i, int j) {
if (visited[i][j]) return;
if (visited[i][j])
return;
visited[i][j] = true;
for (int dir = 0; dir < 4; dir++) {
switch(dir) {
switch (dir) {
case 0:
if (j + 1 < M && grid[i][j + 1] == val) {
search(val, i, j + 1);

View File

@@ -7,6 +7,7 @@ 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 {
@@ -53,7 +54,6 @@ public class MaximumAura {
out.print((left[i] + right[i] - 1) + " ");
}
br.close();
out.flush();

View File

@@ -5,14 +5,14 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class WeightedDifference {
public static void main(String[] args) throws IOException{
// 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();
double t = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Write code here
int a = Integer.parseInt(br.readLine());
@@ -42,7 +42,7 @@ public class WeightedDifference {
}
System.out.println(max);
System.out.println(System.currentTimeMillis()-t);
System.out.println(System.currentTimeMillis() - t);
}