-
Notifications
You must be signed in to change notification settings - Fork 24
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
Hao Wang
committed
Dec 15, 2017
1 parent
3e6824c
commit 992ae7e
Showing
7,412 changed files
with
80,942 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Binary file added
BIN
+1.82 MB
491AdvCompetitiveAlgorithmProg/Slides/fa17_lecture13_advanced_search.pdf
Binary file not shown.
Binary file added
BIN
+259 KB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture10_contest_strategy.pdf
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.04 MB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture12_combinatorial_games.pdf
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.24 MB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture2_data_structures.pdf
Binary file not shown.
Binary file added
BIN
+243 KB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture3_intro_to_graphs_and_search.pdf
Binary file not shown.
Binary file added
BIN
+566 KB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture4_adhoc_simulation.pdf
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.02 MB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture6_basic_graph.pdf
Binary file not shown.
Binary file added
BIN
+4.52 MB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture7_computational_geometry.pdf
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+398 KB
491AdvCompetitiveAlgorithmProg/Slides/fall17_lecture9_intermediate_dp.pdf
Binary file not shown.
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,35 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.lang.*; | ||
public class Main | ||
{ | ||
public static void main(String args[]) throws Exception | ||
{ | ||
int counter = 1; | ||
Scanner cin=new Scanner(System.in); | ||
int stacks=cin.nextInt(); | ||
while(stacks!=0) | ||
{ | ||
int[] numbers = new int[stacks]; | ||
int result = 0; | ||
int sum = 0; | ||
int avg = 0; | ||
for (int i=0; i<stacks; i++) | ||
{ | ||
numbers[i] = cin.nextInt(); | ||
sum = sum + numbers[i]; | ||
} | ||
avg = sum/stacks; | ||
for (int j=0; j<stacks; j++) | ||
{ | ||
result = result + Math.abs(numbers[j]-avg); | ||
} | ||
result = result/2; | ||
|
||
System.out.println("Set #"+counter); | ||
System.out.println("The minimum number of moves is "+result+".\n"); | ||
counter = counter + 1; | ||
stacks=cin.nextInt(); | ||
} | ||
} | ||
} |
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,25 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.lang.*; | ||
public class Main | ||
{ | ||
public static void main(String args[]) throws Exception | ||
{ | ||
Scanner cin=new Scanner(System.in); | ||
int counter=cin.nextInt(); | ||
for (int i=0; i<counter; i++) | ||
{ | ||
double r=cin.nextDouble(); | ||
double e=cin.nextDouble(); | ||
double c=cin.nextDouble(); | ||
if (r<(e-c)) | ||
{ | ||
System.out.println("advertise"); | ||
}else if (r>(e-c)) { | ||
System.out.println("do not advertise"); | ||
}else{ | ||
System.out.println("does not matter"); | ||
} | ||
} | ||
} | ||
} |
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,43 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.lang.*; | ||
public class Main | ||
{ | ||
public static void main(String args[]) throws Exception | ||
{ | ||
Scanner cin=new Scanner(System.in); | ||
String data = cin.nextLine(); | ||
while (!data.equals("*")) | ||
{ | ||
String[] parts = data.split(""); | ||
int length = parts.length; | ||
boolean surprising = true; | ||
for (int i=1; i<length; i++) | ||
{ | ||
Map library = new HashMap(); | ||
for (int j=0; j<length-i; j++) { | ||
if (library.containsKey(parts[j].concat(parts[j+i]))) | ||
{ | ||
surprising = false; | ||
break; | ||
}else | ||
{ | ||
library.put(parts[j].concat(parts[j+i]),1); | ||
} | ||
} | ||
if (surprising==false) | ||
{ | ||
break; | ||
} | ||
} | ||
if (surprising) | ||
{ | ||
System.out.println(data+" is surprising."); | ||
}else | ||
{ | ||
System.out.println(data+" is NOT surprising."); | ||
} | ||
data = cin.nextLine(); | ||
} | ||
} | ||
} |
Binary file not shown.
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,124 @@ | ||
#include <cstdio> | ||
#include <vector> | ||
#include <utility> | ||
#include <bitset> | ||
#include <queue> | ||
#include <algorithm> | ||
#include <cstring> | ||
#include <set> | ||
using namespace std; | ||
|
||
typedef pair<int, int> ii; | ||
typedef vector<int> vi; | ||
typedef vector<ii> vii; | ||
|
||
#define INF 1e9 | ||
#define MAX_V 55 | ||
|
||
int res[MAX_V][MAX_V], mf, f, s, t; | ||
vector<vi> AdjList; | ||
vi p; | ||
|
||
int n, m, cnt = 1; | ||
|
||
bitset<MAX_V> dfsv; | ||
set<int> SSet; | ||
|
||
void dfs(int u) { | ||
dfsv.set(u); | ||
SSet.insert(u); | ||
for (int i = 0; i < (int) AdjList[u].size(); i++) { | ||
int v = AdjList[u][i]; | ||
if (!dfsv.test(v) && res[u][v] > 0) { | ||
dfs(v); | ||
} | ||
} | ||
} | ||
|
||
void mincut() { | ||
SSet.clear(); | ||
for (int i = 0; i < MAX_V; i++) | ||
dfsv.reset(); | ||
dfs(s); | ||
set<int>::iterator it; | ||
|
||
for (it = SSet.begin(); it != SSet.end(); it++) { | ||
int u = *it; | ||
for (int i = 0; i < (int) AdjList[u].size(); i++) { | ||
int v = AdjList[u][i]; | ||
if (SSet.count(v)) | ||
continue; | ||
if (res[u][v] <= 0) { | ||
printf("%d %d\n", u + 1, v + 1); | ||
} | ||
} | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void augment(int v, int minEdge) { | ||
if (v == s) { | ||
f = minEdge; | ||
return; | ||
} else if (p[v] != -1) { | ||
augment(p[v], min(minEdge, res[p[v]][v])); | ||
res[p[v]][v] -= f; | ||
res[v][p[v]] += f; | ||
} | ||
} | ||
|
||
void EdmondKarps() { | ||
mf = 0; | ||
while (1) { | ||
f = 0; | ||
bitset<MAX_V> visited; | ||
visited.set(s); | ||
queue<int> q; | ||
q.push(s); | ||
p.assign(MAX_V, -1); | ||
while (!q.empty()) { | ||
int u = q.front(); | ||
q.pop(); | ||
if (u == t) | ||
break; | ||
for (int i = 0; i < (int) AdjList[u].size(); i++) { | ||
int v = AdjList[u][i]; | ||
if (res[u][v] > 0 && !visited.test(v)) { | ||
visited.set(v); | ||
q.push(v); | ||
p[v] = u; | ||
} | ||
} | ||
} | ||
augment(t, INF); | ||
if (f == 0) | ||
break; | ||
mf += f; | ||
} | ||
} | ||
|
||
int main() { | ||
while (scanf("%d %d", &n, &m), n || m) { | ||
memset(res, 0, sizeof res); | ||
AdjList.assign(n, vi()); | ||
|
||
s = 0; | ||
t = 1; | ||
|
||
for (int i = 0; i < m; i++) { | ||
int u, v, w; | ||
scanf("%d %d %d", &u, &v, &w); | ||
u--; | ||
v--; | ||
res[u][v] += w; | ||
res[v][u] += w; | ||
AdjList[u].push_back(v); | ||
AdjList[v].push_back(u); | ||
} | ||
|
||
EdmondKarps(); | ||
mincut(); | ||
} | ||
|
||
return 0; | ||
} |
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,34 @@ | ||
import java.util.*; | ||
import java.io.*; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner in = new Scanner(System.in); | ||
int testcase = in.nextInt(); | ||
while (testcase-- > 0) { | ||
int number = in.nextInt(); | ||
int xor = 0; | ||
boolean allOnes = true; | ||
for (int i = 1; i <= number; ++i) { | ||
int temp = in.nextInt(); | ||
if (temp != 1) { | ||
allOnes = false; | ||
} | ||
xor ^= temp; | ||
} | ||
if (allOnes) { | ||
if (xor == 0) { | ||
System.out.println("John"); | ||
} else { | ||
System.out.println("Brother"); | ||
} | ||
} else { | ||
if (xor == 0) { | ||
System.out.println("Brother"); | ||
} else { | ||
System.out.println("John"); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,115 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <algorithm> | ||
#define LLU unsigned long long | ||
using namespace std; | ||
struct status { | ||
char board[4][4]; | ||
int ix, iy; | ||
} init; | ||
int pos[16][2], mxdep; | ||
int dir[4][2] = {{0,-1},{-1,0},{1,0},{0,1}};/*u,l,r,d*/ | ||
char dirc[4] = {'L', 'U', 'D', 'R'}, path[100]; | ||
int solved; | ||
bool solvable() { | ||
int sum = 0, row, i, j; | ||
for(i = 0; i < 16; i++) { | ||
if(init.board[i/4][i%4] == 0) { | ||
row = i/4 + 1; | ||
continue; | ||
} | ||
for(j = i+1; j < 16; j++) { | ||
if(init.board[j/4][j%4] < init.board[i/4][i%4]) { | ||
if(init.board[j/4][j%4]) | ||
sum++; | ||
} | ||
} | ||
} | ||
return 1-(sum+row)%2; | ||
} | ||
int H() { | ||
static int i, j, sum, num; | ||
sum = 0; | ||
for(i = 0; i < 4; i++) { | ||
for(j = 0; j < 4; j++) { | ||
num = init.board[i][j]; | ||
if(num == 0) | ||
continue; | ||
sum += abs(i-pos[num][0]) + abs(j-pos[num][1]); | ||
} | ||
} | ||
return sum; | ||
} | ||
int Htable[4][4][16]; | ||
int IDA(int dep, int hv, int prestep) { | ||
if(hv == 0) { | ||
solved = dep; | ||
path[dep] = '\0'; | ||
puts(path); | ||
return dep; | ||
} | ||
if(dep + 5*hv/3 > mxdep) { | ||
return dep + 5*hv/3; | ||
} | ||
int i, tx, ty, x = init.ix, y = init.iy; | ||
int submxdep = 0xfff, val = 0xfff, shv; | ||
|
||
for(i = 0; i < 4; i++) { | ||
if(i + prestep == 3) continue; | ||
tx = x + dir[i][0], ty = y + dir[i][1]; | ||
if(tx < 0 || ty < 0 || tx > 3 || ty > 3) | ||
continue; | ||
|
||
shv = hv; | ||
shv -= Htable[tx][ty][init.board[tx][ty]]; | ||
shv += Htable[x][y][init.board[tx][ty]]; | ||
init.ix = tx, init.iy = ty; | ||
swap(init.board[x][y], init.board[tx][ty]); | ||
|
||
path[dep] = dirc[i]; | ||
val = IDA(dep+1, shv, i); | ||
|
||
swap(init.board[x][y], init.board[tx][ty]); | ||
init.ix = x, init.iy = y; | ||
if(solved) return solved; | ||
submxdep = min(submxdep, val); | ||
} | ||
return submxdep; | ||
} | ||
int main() { | ||
int test, i, j, k, initH; | ||
int cases = 0; | ||
for(i = 0, k = 0; i < 4; i++) | ||
for(j = 0; j < 4; j++) | ||
pos[++k][0] = i, pos[k][1] = j; | ||
for(i = 0; i < 4; i++) | ||
for(j = 0; j < 4; j++) | ||
for(k = 1; k < 16; k++) | ||
Htable[i][j][k] = abs(i - pos[k][0]) + abs(j - pos[k][1]); | ||
scanf("%d", &test); | ||
while(test--) { | ||
cases++; | ||
for(i = 0; i < 4; i++) { | ||
for(j = 0; j < 4; j++) { | ||
scanf("%d", &k); | ||
init.board[i][j] = k; | ||
if(init.board[i][j] == 0) { | ||
init.ix = i, init.iy = j; | ||
} | ||
} | ||
} | ||
if(solvable()) { | ||
solved = 0, initH = mxdep = H(); | ||
if(!mxdep) { | ||
puts(""); | ||
continue; | ||
} | ||
while(solved == 0) | ||
mxdep = IDA(0, initH, -1); | ||
//printf("%d\n", solved); | ||
}else { | ||
puts("This puzzle is not solvable."); | ||
} | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.