-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
507 additions
and
91 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Created by mohammad on 7/24/16. | ||
*/ | ||
import java.util.*; | ||
|
||
public class DFSStack { | ||
static int dfs(ArrayList<ArrayList<Integer>> graph, int start, int end){ | ||
int[] dist = new int[graph.size()]; | ||
|
||
Stack<Integer> stack = new Stack<>(); | ||
Set<Integer> visited = new HashSet<>(); | ||
|
||
stack.push(start); | ||
visited.add(start); | ||
dist[start] = 0; | ||
|
||
while(!stack.isEmpty()){ | ||
int current = stack.pop(); | ||
int d = dist[current]; | ||
if(current == end) return d; | ||
|
||
/*for (int adj : graph.get(current)){ | ||
if (!visited.contains(adj)){ | ||
visited.add(adj); | ||
stack.pop(); | ||
dist[adj] = d+1; | ||
} | ||
}*/ | ||
} | ||
return -1; | ||
} | ||
|
||
public static void main(String[] args){ | ||
Scanner sc = new Scanner(System.in); | ||
int n, e, s, b; | ||
n = sc.nextInt(); | ||
e = sc.nextInt(); | ||
s = sc.nextInt(); | ||
b = sc.nextInt(); | ||
|
||
int u,v; | ||
ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); | ||
for (int i = 0; i < n; i++) | ||
graph.add(new ArrayList<Integer>()); | ||
for (int i = 0; i < e; i++){ | ||
u = sc.nextInt(); | ||
v = sc.nextInt(); | ||
graph.get(u).add(v); | ||
graph.get(v).add(u); | ||
} | ||
int dist = dfs(graph, s, b); | ||
int min = dist / 6 + (dist % 6 == 0 ? 0 : 1); //Not a part of bfs, specifically for Problem 2 of PCS | ||
System.out.println(min + " " + dist); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Created by mo on 10/2/16. | ||
*/ | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
import static java.lang.Math.*; | ||
|
||
|
||
public class Hardy_Ramanujan_Partitions { | ||
static double e = E; | ||
static double c = PI * (sqrt(2) / sqrt(3)); | ||
public static void main(String[] args) { | ||
FastScanner sc = new FastScanner(); | ||
System.out.println(partition(sc.nextInt())); | ||
} | ||
public static double partition(int n){ | ||
/* | ||
Calculates the number of unordered ways to partition a number | ||
in constant time. Accurate in terms of percentage, but not as accurate on smaller cases. | ||
Perhaps code two different versions, one for small numbers, one for large? | ||
*/ | ||
double numerator = pow(e, c * sqrt(n)); | ||
double denominator = (4 * n * sqrt(3)); | ||
return numerator / denominator; | ||
} | ||
|
||
public static class FastScanner { | ||
BufferedReader br; | ||
StringTokenizer st; | ||
|
||
public FastScanner(Reader in) { | ||
br = new BufferedReader(in); | ||
} | ||
|
||
public FastScanner() { | ||
this(new InputStreamReader(System.in)); | ||
} | ||
|
||
String next() { | ||
while (st == null || !st.hasMoreElements()) { | ||
try { | ||
st = new StringTokenizer(br.readLine()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return st.nextToken(); | ||
} | ||
|
||
int nextInt() { | ||
return Integer.parseInt(next()); | ||
} | ||
|
||
long nextLong() { | ||
return Long.parseLong(next()); | ||
} | ||
|
||
double nextDouble() { | ||
return Double.parseDouble(next()); | ||
} | ||
|
||
String readNextLine() { | ||
String str = ""; | ||
try { | ||
str = br.readLine(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return str; | ||
} | ||
|
||
int[] readIntArray(int n) { | ||
int[] a = new int[n]; | ||
for (int idx = 0; idx < n; idx++) { | ||
a[idx] = nextInt(); | ||
} | ||
return a; | ||
} | ||
|
||
long[] readLongArray(int n) { | ||
long[] a = new long[n]; | ||
for (int idx = 0; idx < n; idx++) { | ||
a[idx] = nextLong(); | ||
} | ||
return a; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Created by mo on 10/5/16. | ||
*/ | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class Kadane { | ||
public static void main(String[] args) { | ||
FastScanner sc = new FastScanner(); | ||
int T = sc.nextInt(); | ||
for (int i = 0; i < T; i++){ | ||
int n = sc.nextInt(); | ||
int[] in = new int[n]; | ||
for (int j = 0; j < n; j++) | ||
in[j] = sc.nextInt(); | ||
int out = biggestSubSum(in); | ||
for (int j = 0; j < n; j++){ | ||
int temp = in[j]; | ||
in[j] = 0; | ||
int check = biggestSubSum(in); | ||
//System.err.println(check); | ||
out = check > out ? check : out; | ||
in[j] = temp; | ||
} | ||
System.out.println(out); | ||
} | ||
} | ||
public static int biggestSubSum (int[] arr) { | ||
int maxHere = arr[0], maxSoFar = arr[0]; | ||
for (int i = 0; i < arr.length; i++){ | ||
maxHere = Math.max(Integer.MIN_VALUE, maxHere + arr[i]); | ||
maxSoFar = Math.max(maxSoFar, maxHere); | ||
} | ||
return maxSoFar; | ||
} | ||
public static class FastScanner { | ||
BufferedReader br; | ||
StringTokenizer st; | ||
|
||
public FastScanner(Reader in) { | ||
br = new BufferedReader(in); | ||
} | ||
|
||
public FastScanner() { | ||
this(new InputStreamReader(System.in)); | ||
} | ||
|
||
String next() { | ||
while (st == null || !st.hasMoreElements()) { | ||
try { | ||
st = new StringTokenizer(br.readLine()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return st.nextToken(); | ||
} | ||
|
||
int nextInt() { | ||
return Integer.parseInt(next()); | ||
} | ||
|
||
long nextLong() { | ||
return Long.parseLong(next()); | ||
} | ||
|
||
double nextDouble() { | ||
return Double.parseDouble(next()); | ||
} | ||
|
||
String readNextLine() { | ||
String str = ""; | ||
try { | ||
str = br.readLine(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return str; | ||
} | ||
|
||
int[] readIntArray(int n) { | ||
int[] a = new int[n]; | ||
for (int idx = 0; idx < n; idx++) { | ||
a[idx] = nextInt(); | ||
} | ||
return a; | ||
} | ||
|
||
long[] readLongArray(int n) { | ||
long[] a = new long[n]; | ||
for (int idx = 0; idx < n; idx++) { | ||
a[idx] = nextLong(); | ||
} | ||
return a; | ||
} | ||
} | ||
} |
Oops, something went wrong.