Skip to content

Instantly share code, notes, and snippets.

@longthtran
longthtran / OPCPIZZA
Created September 28, 2017 05:26
Pizzamania spoj java solution
import java.io.DataInputStream;
import java.io.InputStream;
import java.util.Arrays;
class Main {
public static int cntRemainBinarySearch(int[]a, int left, int right, int x) {
int tRight = right;
@longthtran
longthtran / MinimumLoss1.java
Created September 28, 2017 02:54
This version is much shorter than the previous code that I use data structure in Java TreeSet. Each time we meet new element then we 'll find the smallest element in the TreeSet but greater than or equal to it which takes complexity O(logN).
import java.io.DataInputStream;
import java.io.InputStream;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
@longthtran
longthtran / SHPATH java spoj
Last active September 11, 2017 18:28
The shortest path java spoj
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
@longthtran
longthtran / Main.java
Last active September 21, 2019 17:46
Validate the maze java spoj
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
class Main {
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i< n; i++) {
int a = in.nextInt();
@longthtran
longthtran / Minimumloss.java
Last active December 12, 2016 03:18
Using binary search tree and the complexity is O(n*log) - for each element in the input n elements array, we will insert that element to the binary tree and find the smallest upper node which is bigger than its value (this operation took us O(logn) )
import java.io.*;
import java.util.*;
class BinaryTree {
BinaryTree left;
BinaryTree right;
long value;
public BinaryTree (long val) {
this.value = val;
}