comments for bob solutions
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// Full solved correct solution
|
||||||
public class DealEmOut {
|
public class DealEmOut {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
//Incomplete Not Working
|
||||||
public class DontTestMe {
|
public class DontTestMe {
|
||||||
public static void main(String[] args) throws IOException{
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
|
||||||
@@ -15,38 +16,36 @@ public class DontTestMe {
|
|||||||
int N = Integer.parseInt(st.nextToken());
|
int N = Integer.parseInt(st.nextToken());
|
||||||
int H = Integer.parseInt(st.nextToken());
|
int H = Integer.parseInt(st.nextToken());
|
||||||
Test[] ar = new Test[N];
|
Test[] ar = new Test[N];
|
||||||
for (int i =0; i < N; i++){
|
for (int i = 0; i < N; i++) {
|
||||||
st = new StringTokenizer(br.readLine());
|
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{
|
class Test {
|
||||||
int hours,points;
|
int hours, points;
|
||||||
double percent;
|
double percent;
|
||||||
double weight;
|
double weight;
|
||||||
|
|
||||||
public Test (int h, int p, double per){
|
public Test(int h, int p, double per) {
|
||||||
hours = h;
|
hours = h;
|
||||||
points = p;
|
points = p;
|
||||||
percent = per;
|
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;
|
Test t = (Test) o;
|
||||||
if (this.weight > t.weight) return 1;
|
if (this.weight > t.weight)
|
||||||
else if (this.weight < t.weight) return -1;
|
return 1;
|
||||||
|
else if (this.weight < t.weight)
|
||||||
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
//Nearly correct solution...one/two bugs passed most testcases
|
||||||
public class Island {
|
public class Island {
|
||||||
static int N, M;
|
static int N, M;
|
||||||
static int[][] grid;
|
static int[][] grid;
|
||||||
static boolean[][] visited;
|
static boolean[][] visited;
|
||||||
static Map<Integer, Integer> islands = new HashMap<>();
|
static Map<Integer, Integer> islands = new HashMap<>();
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||||
@@ -29,7 +31,8 @@ public class Island {
|
|||||||
br.close();
|
br.close();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
for (int j = 0; j < M; j++) {
|
for (int j = 0; j < M; j++) {
|
||||||
if (visited[i][j]) continue;
|
if (visited[i][j])
|
||||||
|
continue;
|
||||||
if (grid[i][j] > 0) {
|
if (grid[i][j] > 0) {
|
||||||
islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1);
|
islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1);
|
||||||
search(grid[i][j], i, j);
|
search(grid[i][j], i, j);
|
||||||
@@ -50,10 +53,11 @@ public class Island {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void search(int val, int i, int j) {
|
static void search(int val, int i, int j) {
|
||||||
if (visited[i][j]) return;
|
if (visited[i][j])
|
||||||
|
return;
|
||||||
visited[i][j] = true;
|
visited[i][j] = true;
|
||||||
for (int dir = 0; dir < 4; dir++) {
|
for (int dir = 0; dir < 4; dir++) {
|
||||||
switch(dir) {
|
switch (dir) {
|
||||||
case 0:
|
case 0:
|
||||||
if (j + 1 < M && grid[i][j + 1] == val) {
|
if (j + 1 < M && grid[i][j + 1] == val) {
|
||||||
search(val, i, j + 1);
|
search(val, i, j + 1);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.PrintWriter;
|
|||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
import java.util.StringTokenizer;
|
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 class MaximumAura {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
@@ -53,7 +54,6 @@ public class MaximumAura {
|
|||||||
out.print((left[i] + right[i] - 1) + " ");
|
out.print((left[i] + right[i] - 1) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
// Working but O(n*n) --> 50% of test cases fail on time complexity
|
||||||
public class WeightedDifference {
|
public class WeightedDifference {
|
||||||
public static void main(String[] args) throws IOException{
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
double t = System.currentTimeMillis();
|
double t = System.currentTimeMillis();
|
||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
|
||||||
|
|
||||||
// Write code here
|
// Write code here
|
||||||
|
|
||||||
int a = Integer.parseInt(br.readLine());
|
int a = Integer.parseInt(br.readLine());
|
||||||
@@ -42,7 +42,7 @@ public class WeightedDifference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(max);
|
System.out.println(max);
|
||||||
System.out.println(System.currentTimeMillis()-t);
|
System.out.println(System.currentTimeMillis() - t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user