This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void insertionSort(int[] ar) { | |
| if (ar == null || ar.length == 0) { | |
| return; | |
| } | |
| int tmp = ar[ar.length - 1]; | |
| int i = ar.length - 2; | |
| while (i >= 0 && ar[i] > tmp) { | |
| ar[i + 1] = ar[i]; | |
| i -= 1; | |
| printArray(ar); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.math.BigInteger; | |
| public class Lego_Blocks { | |
| public static void main(String[] args) { | |
| lego(new int[][] {{2, 2}, {3, 2}, {2, 3}, {4, 4}, {1, 10}, {10, 10}, {20, 20}}); | |
| } | |
| public static void lego(int[][] arr) { | |
| boolean debug = true; | |
| int width, height; | |
| BigInteger[] P, N; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Longest_Product_Subarray { | |
| /** | |
| * Given a double array, find the longest sub-array, whose product is the | |
| * largest. E.g., given {-2.5, 4, 0, 3, 0.5, 8, -1}, the longest sub-array | |
| * with max product is {3, 0.5, 8} | |
| * | |
| * @param args | |
| */ | |
| public static void main(String[] args) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Raquetball { | |
| /** | |
| * @param args | |
| */ | |
| public static void main(String[] args) { | |
| // TODO Auto-generated method stub | |
| int totalTrial = 1000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Fair_and_Square { | |
| public static void main(String[] args) { | |
| solve(1, 4, 1); | |
| solve(10, 120, 1); | |
| solve(100, 1000, 1); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| class Treasure { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int T, t, K, k, N, n; | |
| ArrayList<ArrayList<Integer>> chests; | |
| int[] keys; | |
| T = sc.nextInt(); | |
| for (t = 1; t <= T; ++t) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Cell: | |
| def __init__(self, x, y, index): | |
| self.x = x | |
| self.y = y | |
| self.index = index | |
| def __repr__(self): | |
| return repr((self.x, self.y)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def parse(data): | |
| 'Parse a variable length record format' | |
| i = 0 | |
| while i < len(data): | |
| kind = data[i] | |
| i += 1 | |
| if 0: | |
| pass | |
| elif kind == 'p': | |
| lastname = str(data[i:i+8]).rstrip() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void solve(int[] arr, int max, int gain, int n) { | |
| int[] dp = new int[max - gain + 1], next; | |
| int i, j, k, localMax; | |
| for (i = 0; i <= max - gain; ++i) { | |
| dp[i] = (max - i) * arr[0]; | |
| } | |
| //printArray(dp); | |
| for (i = 1; i < n; ++i) { | |
| next = new int[max - gain + 1]; | |
| for (j = 0; j <= max - gain; ++j) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sets import Set | |
| class DominoChecker: | |
| def __init__(self): | |
| self.container = Set() | |
| def addBox(self, str): | |
| arr = [char for char in str] |
OlderNewer