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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int intcmp(const void *a, const void *b) { | |
| return *((int *)a) - *((int *)b); | |
| } | |
| int min_coins(int coins[], size_t ncoins, int target) { | |
| if (ncoins <=0 ) return 0; | |
| qsort(coins, ncoins, sizeof(int), &intcmp); |
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
| #include <stdio.h> | |
| struct padded { | |
| short s; | |
| int i; | |
| }; | |
| int main(int argc, char **argv) { | |
| // this should give in memory (8 bytes): | |
| // 0xffff1234, 0x00005678 |
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 final class Circuits { | |
| public static int howLong(String[] connects, String[] costs) { | |
| final int size = connects.length; | |
| final int[][] m = new int[size][size]; | |
| for (int i=0; i<size; ++i) { | |
| String c = connects[i]; |
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 final class PathFinding { | |
| static final class State { | |
| final int ax, ay, bx, by; | |
| final int hash; | |
| State(int ax, int ay, int bx, int by) { | |
| this.ax = ax; |
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 final class Escape { | |
| private static final int size = 501; | |
| private static final int NotSeen = -1; | |
| private enum Type { | |
| Normal, Harmful, Deadly | |
| } |
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.*; | |
| /** | |
| * SRM 181 Div 1 - 3rd | |
| */ | |
| public class KiloManX { | |
| public static int leastShots(String[] damageChart, int[] bossHealth) { | |
| final int size = bossHealth.length; | |
| final int rows = 1 << size; |
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
| #include<stdio.h> | |
| #include<stdlib.h> | |
| #include<assert.h> | |
| #include<stdbool.h> | |
| #define DUP (-1) | |
| #define INVALID (-2) | |
| static int comp(int a, int b, int c, int d) { | |
| if (a == c) { |
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 final class Zigzag { | |
| private Zigzag() {} | |
| /** | |
| * given an array of integer, returns the maximun length of zig-zag | |
| * subsequence | |
| */ | |
| public static int zigzagSequence(int[] arr) { | |
| if (arr.length < 2) { |
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 LowerBound { | |
| private LowerBound() {} | |
| final static class Node { | |
| Node left, right; | |
| final int val; | |
| public Node(int val) { |
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
| #include<stdio.h> | |
| #include<stdlib.h> | |
| #include<assert.h> | |
| static void swap(int* data, int c) { | |
| for (int i=0; c > 0; i+=2, --c) { | |
| int tmp = data[i]; | |
| data[i] = data[i+1]; | |
| data[i+1] = tmp; | |
| } |