Skip to content

Commit

Permalink
APAC 2016 Explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
shixi_chenzhang committed Apr 24, 2017
1 parent c1f6a3a commit 8f1e11e
Show file tree
Hide file tree
Showing 30 changed files with 249 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Codejam
Codejam, apac, kickstart, I/O for Women... 2017, 2016, 2015, 2014...
https://code.google.com/codejam/past-contests
ALL JAVA SOLUTIONS HERE!
ALL EXPLANATIONS AND JAVA SOLUTIONS HERE!

## Contest List

Expand Down
4 changes: 4 additions & 0 deletions apac/2016/Practice Round/A.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Practice Round Problem A: Bad Horse
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/Practice Round/B.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Practice Round Problem B: Captain Hammer
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/Practice Round/C.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Practice Round Problem C: Moist
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
14 changes: 14 additions & 0 deletions apac/2016/Practice Round/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# APAC 2016 Practice Round
https://code.google.com/codejam/contest/6234486/dashboard

## Problem A: Bad Horse

BFS/DFS to mark color for each horse. Simple.

## Problem B: Captain Hammer

`t=d/v_x=2*v_y/g, ¦È=arcsin(gd/v^2)/2`

## Problem C: Moist

Simple. Keep the current max value.
4 changes: 4 additions & 0 deletions apac/2016/RoundA/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round A Problem A: Googol String
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundA/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round A Problem B: gCube
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundA/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round A Problem C: gCampus
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundA/D.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round A Problem D: gSnake
* Check README.md for explanation.
*/
public class Main {


Expand Down
22 changes: 22 additions & 0 deletions apac/2016/RoundA/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# APAC 2016 Round A
https://code.google.com/codejam/contest/4284486/dashboard

## Problem A: Googol String

Simple. Nothin to tell.

## Problem B: gCube

Simple. `V=PI_(i,l,r) {a[i]}, Edge=pow(V, 1/d).`

## Problem C: gCampus

Floyd to calculate the distance of any two offices.
Then, for each road, if the distance between its two verticals is smaller than
its length, then it's an inefficient road.

## Problem D: gSnake

Brute force. As X<=1000000, we can simulate at most 1100000 seconds.
for every second in [1, 1100000], check if the snake will die, or it can eat food.
Using HashSet to remember all bodies, and all foods eaten.
4 changes: 4 additions & 0 deletions apac/2016/RoundB/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round B Problem A: Travel
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundB/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round B Problem B: gWheels
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundB/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round B Problem C: gNumbers
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
12 changes: 8 additions & 4 deletions apac/2016/RoundB/D.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* APAC 2016 Round B Problem D: Albocede DNA
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand All @@ -11,10 +15,10 @@ private String solve(Scanner scanner) {
long mod=1000000007;
long[][][][] dp=new long[len+1][len/2+3][len/2+3][2];
dp[0][0][0][0]=1;
for (int i=1;i<=len;i++) { // 长度
for (int j=0;j<=len/2;j++) { // a数量
for (int k=0;k<=len/2;k++) { // b数量
for (int l=0;l<2;l++) { // 是否开始处理c或d
for (int i=1;i<=len;i++) { // current chracter
for (int j=0;j<=len/2;j++) { // number of a
for (int k=0;k<=len/2;k++) { // number of b
for (int l=0;l<2;l++) { // whether to deal with c/d
if (s.charAt(i-1)=='a') {
if (k==0) {
dp[i][j+1][k][0]+=dp[i-1][j][k][l];
Expand Down
26 changes: 26 additions & 0 deletions apac/2016/RoundB/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# APAC 2016 Round B
https://code.google.com/codejam/contest/10214486/dashboard

## Problem A: Travel

As `Cost[t] ¡Ü Cost[t+1]+1`, we cannot stop at any city.
So, just for each start time, bfs to find the minimal time.

## Problem B: gWheels

As `p/e*e'/t=P/Q`, we can calculate all possible `e/e'` in the extra
gears. Then, for each p in Np and t in Nt, check if Pt/pQ is possible.

## Problem C: gNumbers

Calculate all factors of n with only one prime. `9075=3*25*121, etc.`
Then dfs with memorization to solve it!

## Problem D: Albocede DNA

It's a really, really difficult problem.
DP, dp[i][j][k][l] where i means the current character, j means
the number of a, k means the number of b, and l means if we have
started to deal with c/d.
Check [D.java](D.java) for more details.

4 changes: 4 additions & 0 deletions apac/2016/RoundC/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round C Problem A: gRanks
* Check README.md for explanation.
*/
public class Main {

class Athlete {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundC/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round C Problem B: gFiles
* Check README.md for explanation.
*/
public class Main {

public String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundC/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round C Problem C: gGames
* Check README.md for explanation.
*/
public class Main {

public String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundC/D.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round C Problem D: gMatrix
* Check README.md for explanation.
*/
public class Main {

public String solve(Scanner scanner) {
Expand Down
25 changes: 25 additions & 0 deletions apac/2016/RoundC/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# APAC 2016 Round C
https://code.google.com/codejam/contest/4284487/dashboard

## Problem A: gRanks

Brute force. Simple.

## Problem B: gFiles

Intervals intersection.
Take care of p=0 and p=100. Use `long` instead of `double`.

## Problem C: gGames

DP/DFS with memorization.
dp[i][x] means, can we put x in first i rounds. Here x records people
(one in a bit).
To solve this, just break x into two numbers y and z, then check dp[i-1][y]
and dp[i-1][z]. Check all possible subsets.
Return `dp[n][(1<<n)-1]`.

## Problem D: gMatrix

First, solve the problem [Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/).
Then, just apply it to each row, then each col.
4 changes: 4 additions & 0 deletions apac/2016/RoundD/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round D Problem A: Dynamic Grid
* Check README.md for explanation.
*/
public class Main {

public String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundD/B.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round D Problem B: gBalloon
* Check README.md for explanation.
*/
public class Main {

public String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundD/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.*;
import java.util.stream.Collectors;

/**
* APAC 2016 Round D Problem C: IP Address Summarization
* Check README.md for explanation.
*/
public class Main {

class Trie {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundD/D.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Round D Problem D: Virtual Rabbit
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
40 changes: 40 additions & 0 deletions apac/2016/RoundD/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# APAC 2016 Round D
https://code.google.com/codejam/contest/11214486/dashboard

## Problem A: Dynamic Grid

Simple problem.
For each query, just bfs is enough.

## Problem B: gBalloon

Solution #1: DP
dp[i][j] means the minimal time of first i balloons with j amounts of energy.
`dp[i][j]=min(max(dp[i-1][j-|h[i]-k|], |p[i]/wind[k]|)) for 1<=k<=m`.
Time complexity: O(mnq)~10^9, large solved in 164.685s.

Solution #2: Binary Search
For each time, check if we can collect all balloons.
Time complexity: O(mn*log(p_max)), large solved in 1.175s

## Problem C: IP Address Summarization

Trie. For each node in trie, mark if it's an end.
If a node is end, remove all sub-trees of it.
If the left and right children of a node are both end, then it's an end.

## Problem D: Virtual Rabbit

For small, just check if `[curr+1, curr+x]` has intersection with
`[day_start+g, dat_start+w-1], [day_start+h, day_start+b-1],
[day_start+86400+g, dat_start+86400+w-1], [day_start+86400+h,
day_start+86400+b-1]`.
Find the max point to be the fed time.

For large, we cannot simulate in the whole process.
What's to do is, find the loop. That is, find two days where
Alice feed the rabbit at the same second.
After finding the loop, we can just calculate how many days in a loop,
how many feed times in a loop, and how many loops there are.
It's hard to implement, please be careful.
Check [D.java](D.java) for more details.
4 changes: 4 additions & 0 deletions apac/2016/RoundE/A.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Round E Problem A: Lazy Spelling Bee
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundE/B.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Round E Problem B: Robot Rock Band
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
4 changes: 4 additions & 0 deletions apac/2016/RoundE/C.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import java.io.PrintStream;
import java.util.*;

/**
* APAC 2016 Round E Problem C: Not So Random
* Check README.md for explanation.
*/
public class Main {

private String solve(Scanner scanner) {
Expand Down
Loading

0 comments on commit 8f1e11e

Please sign in to comment.