Permalink
Browse files

Finished notanix programming contest

  • Loading branch information...
1 parent 3354a3f commit 731d25320e143323b58ca5a6110c7299ee0fbb0a @wonjohnchoi committed Feb 5, 2012
Showing with 730 additions and 0 deletions.
  1. 0 ...ng-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/#easyComputer.js#
  2. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt1.gif
  3. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt10.gif
  4. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt100.gif
  5. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt101.gif
  6. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt102.gif
  7. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt103.gif
  8. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt2.gif
  9. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt201.gif
  10. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt202.gif
  11. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt203.gif
  12. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt204.gif
  13. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt205.gif
  14. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt206.gif
  15. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt3.gif
  16. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt4.gif
  17. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt5.gif
  18. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt6.gif
  19. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt7.gif
  20. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt8.gif
  21. BIN {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/batt9.gif
  22. 0 {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/battleship.htm
  23. 0 {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/easyComputer.js
  24. 0 {coding-for-grub/2011-vertigo → 2011-vertigo-programming-contest}/battleship_student/myAlgorithm.js
  25. +132 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/CodeJamInput/LaundryInput.txt
  26. +64 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/CodeJamInput/LightsOnInput.txt
  27. +158 −0 ...-nutanix-programming-contest/NutanixProgrammingContest/CodeJamInput/MatrixMultiplicationInput.txt
  28. +22 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/CodeJamInput/RevenueMaximizationInput.txt
  29. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/Laundry$Machine.class
  30. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/Laundry.class
  31. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/LightsOn.class
  32. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/MatrixMultiplication$Matrix.class
  33. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/MatrixMultiplication.class
  34. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/MatrixMultiplication2.class
  35. BIN 2012-nutanix-programming-contest/NutanixProgrammingContest/bin/RevenueMaximization.class
  36. +68 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/src/Laundry.java
  37. +46 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/src/LightsOn.java
  38. +102 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/src/MatrixMultiplication.java
  39. +88 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/src/MatrixMultiplication2.java
  40. +50 −0 2012-nutanix-programming-contest/NutanixProgrammingContest/src/RevenueMaximization.java
Oops, something went wrong.
@@ -0,0 +1,22 @@
+21
+9 9 1 5 5 5 5 4 8 80
+3 17 50 2
+50 3 4 5 0 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 90 6
+16 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1
+1 1000
+50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
+36 1 1 1 1 1 1 1 1 1 1 9 19 1 1 1 1 1 1 1 1 1 1 46 47 48 1000 1 1 1 1 1 1 1 1 1 1
+37 1 1 1 1 1 1 1 1 1 1 6 9 18 1 1 1 1 1 1 1 1 1 1 46 47 48 1000 1 1 1 1 1 1 1 1 1 1
+37 1 1 1 1 1 1 1 1 1 1 7 9 18 1 1 1 1 1 1 1 1 1 1 46 47 48 1000 1 1 1 1 1 1 1 1 1 1
+8 130 110 90 17 6 5 4 3
+9 130 110 90 13 6 5 4 3 0
+8 130 110 90 4 6 5 4 3
+6 18 0 20 0 1 0
+2 0 0
+20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000
+20 19 99 34 78 67 75 77 36 23 3 3 9 66 34 34 34 34 34 34 66
+2 111 22
+39 130 110 90 13 6 5 4 3 0 130 110 90 15 15 15 13 6 5 4 3 0 130 110 90 13 6 5 4 3 0 130 110 90 13 6 5 4 3 0
+9 130 110 90 13 6 5 4 3 0
+3 1 1 1
+50 1 1 3 3 3 4 4 5 6 1000 1 1 3 3 3 4 4 5 6 1000 1 1 3 3 3 4 4 5 6 1000 1 1 3 3 3 4 4 5 6 1000 1 1 3 3 3 4 4 5 6 1000
@@ -0,0 +1,68 @@
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Scanner;
+
+/**
+ *
+ * @author wonjohnchoi
+ *
+ */
+public class Laundry {
+ public static void main(String args[]) {
+ Scanner in = new Scanner(System.in);
+ int t = in.nextInt();
+ for (int i = 0;i < t; i += 1) {
+
+ long nCoins = in.nextLong();
+ int nMachines = in.nextInt();
+ long required[] = new long[nMachines];
+ long returned[] = new long[nMachines];
+
+ for (int j = 0; j < nMachines; j += 1) {
+ required[j] = in.nextLong();
+ }
+
+
+ for (int j = 0; j < nMachines; j += 1) {
+ returned[j] = in.nextLong();
+ }
+
+ LinkedList<Machine> machines = new LinkedList<Machine>();
+ for (int j = 0; j < nMachines; j += 1) {
+ machines.add(new Machine(required[j], returned[j]));
+ }
+
+ Collections.sort(machines);
+ int nWashes = 0;
+
+ while (!machines.isEmpty()) {
+ Machine cur = machines.remove();
+ //System.out.println("Using machine: " + cur.required + " " +cur.returned);
+ if (nCoins >= cur.required) {
+ long usable = nCoins - cur.required;
+ //System.out.println(cur.required + " " + cur.returned + " " + cur.diff);
+ long washes = usable / cur.diff + 1;
+ nWashes += washes;
+ nCoins -= nWashes * cur.diff;
+ }
+ }
+
+ System.out.println(nWashes);
+ }
+ }
+
+ static class Machine implements Comparable<Machine>{
+ long required;
+ long returned;
+ long diff;
+ Machine(long required, long returned) {
+ this.required = required;
+ this.returned =returned;
+ diff = required - returned;
+ }
+ @Override
+ public int compareTo(Machine arg0) {
+ return (int)(diff - arg0.diff);
+ }
+ }
+}
@@ -0,0 +1,46 @@
+import java.util.Scanner;
+
+/**
+ *
+ * @author wonjohnchoi
+ *
+ */
+public class LightsOn {
+ public static void main(String args[]) {
+ Scanner in = new Scanner (System.in);
+
+ int t = in.nextInt();
+ in.nextLine();
+ for (int i = 0; i < t; i += 1) {
+ String line = in.nextLine();
+ String[] data = line.split(",");
+ boolean[][] table = new boolean[data.length][data[0].length()];
+
+ for (int j = 0;j < data.length; j += 1) {
+ for (int k = 0;k < data[j].length(); k += 1) {
+ table[j][k] = data[j].charAt(k) == '1' ? true : false;
+ }
+ }
+
+ //goal is make everything true;
+ int nSwitch = 0;
+ for (int j = table.length - 1; j >= 0; j -= 1) {
+ for (int k = table[j].length - 1; k >= 0; k -= 1) {
+ if (!table[j][k]) {
+ nSwitch += 1;
+ for (int m = 0; m <= j; m += 1) {
+ for (int n = 0; n <= k; n += 1) {
+ table[m][n] = !table[m][n];
+ }
+ }
+ }
+ }
+ }
+
+ System.out.println(nSwitch);
+
+
+
+ }
+ }
+}
@@ -0,0 +1,102 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.Scanner;
+
+/**
+ *
+ * @author wonjohnchoi
+ *
+ */
+public class MatrixMultiplication {
+ static double time;
+
+ public static void main(String args[]) {
+ //recursive brute force. may run out of time.
+
+ Scanner in = new Scanner(System.in);
+
+ int t = in.nextInt();
+ for (int i = 0; i < t;i += 1) {
+
+ time = System.currentTimeMillis();
+ //System.out.println(i);
+ int n = in.nextInt();
+
+ ArrayList<Matrix> matrices = new ArrayList<Matrix>();
+ for (int j = 0;j < n; j += 1) {
+ matrices.add(new Matrix(in.nextInt(), in.nextInt()));
+ }
+
+ Integer result = mul(matrices);
+ if (result == null) {
+ System.out.println(-1);
+ } else {
+ System.out.println(result);
+ }
+ }
+ }
+
+ private static Integer mul(ArrayList<Matrix> matrices) {
+ if (System.currentTimeMillis() - time >= 400) {
+ return null;
+ }
+ //System.out.println(matrices.size());
+ if (matrices.size() == 1) {
+ return matrices.get(0).m * matrices.get(0).n;
+ }
+
+ int max = Integer.MIN_VALUE;
+ for (int i = 0; i < matrices.size(); i += 1) {
+ for (int j = i + 1; j < matrices.size(); j += 1) {
+ LinkedList<Matrix> matrix = matrices.get(i).mul(matrices.get(j));
+ if (matrix.size() != 0) {
+ for (Matrix m : matrix) {
+ Matrix m1, m2;
+
+ matrices.add(m);
+ m1 = matrices.remove(j);
+ m2 = matrices.remove(i);
+
+ Integer val = mul(matrices);
+ if (val != null) {
+ max = Math.max(max, val);
+ }
+
+ matrices.add(i, m2);
+ matrices.add(j, m1);
+ matrices.remove(matrices.size() - 1);
+ }
+ }
+ }
+ }
+
+ if (max == Integer.MIN_VALUE) {
+ return null;
+ } else {
+ return max;
+ }
+ }
+
+ static class Matrix {
+
+ int m;
+ int n;
+ Matrix(int newM, int newN) {
+ m = newM;
+ n = newN;
+ }
+
+ LinkedList<Matrix> mul(Matrix matrix) {
+ LinkedList<Matrix> poss = new LinkedList<Matrix>();
+ if (n == matrix.m) {
+ poss.add(new Matrix(m, matrix.n));
+ }
+
+ if (m == matrix.n) {
+ poss.add(new Matrix(n, matrix.m));
+ }
+
+ return poss;
+ }
+ }
+}
@@ -0,0 +1,88 @@
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.Scanner;
+
+/**
+ *
+ * @author wonjohnchoi
+ *
+ */
+public class MatrixMultiplication2 {
+ static double time;
+
+ public static void main(String args[]) {
+ //recursive brute force. may run out of time.
+
+ Scanner in = new Scanner(System.in);
+
+
+ /*
+ * 49
+3
+-1
+-1
+
+1
+10
+81
+1000
+1000000
+1000
+1000000
+-1
+255025
+909000
+-1
+-1
+36
+16
+ */
+ int t = in.nextInt();
+ for (int i = 0; i < t;i += 1) {
+
+ //System.out.println(i);
+ int n = in.nextInt();
+
+ boolean[][] graph = new boolean[1001][1001];
+ for (int j = 0; j < n; j += 1) {
+ graph[in.nextInt()][in.nextInt()] = true;
+ }
+
+ for (int j = 0; j < graph.length; j += 1) {
+ for (int k = 0; k < graph.length; k += 1) {
+ for (int l = 0; l < graph.length; l += 1) {
+ if (graph[j][k] && graph[k][l]) {
+ graph[j][k] = false;
+ graph[k][l] = false;
+ graph[j][l] = true;
+ }
+ }
+ }
+ }
+
+ boolean found = false;
+ boolean bad = false;
+ int ans = 0;
+ for (int j = 0; j < graph.length; j += 1) {
+ for (int k = 0; k < graph.length; k += 1) {
+ if (graph[j][k]) {
+ if (found) {
+ bad = true;
+ }
+ found = true;
+ ans = j * k;
+ }
+ }
+ }
+
+ if (bad) {
+ System.out.println(-1);
+ continue;
+ }
+ System.out.println(ans);
+
+
+
+ }
+ }
+}
@@ -0,0 +1,50 @@
+import java.util.Arrays;
+import java.util.Scanner;
+
+/**
+ *
+ * @author wonjohnchoi
+ *
+ */
+public class RevenueMaximization {
+ public static void main(String args[]) {
+ Scanner in = new Scanner(System.in);
+
+ int t = in.nextInt();
+
+ for (int i = 0; i < t; i += 1) {
+ int n = in.nextInt();
+
+ int[] ps = new int[n];
+ for (int j = 0; j < n; j += 1) {
+ ps[j] = in.nextInt();
+ }
+ Arrays.sort(ps);
+
+ //n<=4
+ int ans = 0;
+ if (n <= 4) {
+ for (int j = 0;j < n;j += 1) {
+ ans += ps[j];
+ }
+ System.out.println(ans);
+ continue;
+ }
+
+ //System.out.println(Arrays.toString(ps));
+ //brute force
+ ans = Integer.MIN_VALUE;
+ for (int j = 0;j < n ;j += 1) {
+ for (int k = j + 1; k < n ;k += 1) {
+ for (int m = k + 1; m < n; m += 1) {
+ for (int v = m + 1; v < n; v += 1) {
+ ans = Math.max(ans, ps[j] * (k - j) + ps[k] * (m - k) + ps[m] * (v - m) + ps[v] * (n - v));
+ //System.out.println("ans:"+ans+" "+j+" "+k+" "+m+" "+v);
+ }
+ }
+ }
+ }
+ System.out.println(ans);
+ }
+ }
+}

0 comments on commit 731d253

Please sign in to comment.