Processing math: 100%

Labels

Recent Posts

Monday, April 15, 2013

Math Proofs of Google Code Jam Qualification Round 2013 Problems


Problems of Google Code Jam Qualification Round 2013 can be found at http://code.google.com/codejam/contest/2270488/dashboard

1 Problem A. Tic-Tac-Toe-Tomek

No math involved, but complex number is builtin in python and go, so I use 0,i,1,1 to represent “ “, T, O, X. So if4i=1ai,i>3 , then some one won.

2 Problem B. Lawnmower

Theorem.(ai,j) is a possible pattern if ai,j=min(max({ai,k}),max({ak,j})) for every i,j .
Proof.
Can be easily proved by induction on N=i,jMai,j , where M=max({ai,j}) .
         
     

3 Problem C. Fair and Square

Let N=an10n+an110n1++a110+a0 , where ai{0,1,9} and an0 . Denote by δk(x) the (nk+1) -th digit of x , then we have δk(x)=ak .
Assume N is a palindrome, i.e., ai=an1 for every i .
Let bk be the coefficient of xk of (anxn+an1xn1++a1+a0)2, that is, bk=min(k,n)i=max(0,kn)aiaki.

Theorem. N2 is also a palindrome iff bk9 for all k .
Proof.
( )
Trivial.
( )
Observe that bk=b2nk for all k . We prove the statement by mathematical induction on k for kn .
Case k=0 :
Since a2n102nN2<(an+1)2102n and δ0(N2)=δ0(a20)=δ0(a2n), it is easy to see that a0=an{1,2,3} . So b0=a209 .
Moreover, we also know that N2 has 2n+1 digits and hence δ2nk(N2)=δk(N2) for all k2n .
Case k>0 :
Suppose bi9 for all i<k , we want to show bk9 .
By the induction hypothesis, we know that δ2ni(N2)=δi(N2)=bi=b2ni for all i<k . So
102nk1N2102nk1=2ni=2nk1δi(N2)10i=2ni=2nk1bi10i
On the other hand, N2102nk1=2ni=0bi10i102nk1=2ni=2nk1bi10i102nk1+2nki=0bi10i102nk1. Therefore, 2nki=0bi10i102nk1=0 , hence bk=b2nk2nki=0bi10i102nk<10.
  
  
Corollary. N2 is also a palindrome iff ni=0a2i9 .
Proof.
bn=ni=0aiani=ni=0a2i .
( )
bnbk for every k by Cauchy-Schwarz inequility.
( )
Trivial.
In particular, if N3 , then ai{0,1,2} .

4 Problem D. Treasure

Let TN be the set of all key types. Assume 0T .
Construct a directed graph G=(V,E) as following:
  • V=T{0}
  • (0,j)E iff we starts with at least one key of type j .
  • If i0 , then (i,j)E iff there is a key of type j in a box of type i .bnbk for every palidrone N by Cauchy-Schwarz inequility.
Denote by B(i) the number of boxes of type i and K(i) the total number of keys of type i (including the keys you start with and keys in boxes).

Theorem. All box can be opened iff for every jT , B(j)K(j) and there is a directed path from 0 to j in graph G .
Proof.
( )
If B(j)>K(j) , then we don’t have enough keys of type j to open all boxes of type j .
If there is no path from 0 to j , then it means we are unable to get any key of type j .
( )
We prove this by induction on the number of boxes. Denote by N the number of boxes.
Assume for every jT , B(j)K(j) and there is a directed path from 0 to j in graph G .
Case N=1 :
Then all vertices in G are leaves except 0 and the type of the only box. So there must be an edge from 0 to the type of the box.
Case N>1 :
Suppose the theorem holds for the case with N1 boxes.
There are at least one (0,i)E . Consider we open a box of type i (that contains a key of type i if possible). Assume we destroy the key and the box just opened, then we have a setting of N1 boxes. In this setting, we still have B(j)K(j) for all j . Let G=(V,E) be the directed graph of this (N1) -box setting.
If B(i)=1 , then all children of j in G become children of 0 , 0 can still reach all other types in G .
Assume B(i)>1 .
If (i,i)E , then we can open a box of type i that contains a key of type i .
Otherwise, because K(i)B(i)>1 , we still hold at least one key of type i after we open a box of type i (and destroy the key).
Either way, (0,i)E . Therefore, for every child j of i in G , either
1. (0,j)E (if a key of type j is in the box we just opened), or
2. (i,j)E and so there is a path from 0 to i and then to j .
So 0 can still reach very vertex in G .
By induction hypothesis, the remaining N1 can also be opened.
  
  
By the proof of the theorem, there is a simple algorithm to open all boxes: open any box unless you have just one key of that type and box does not contain a key that can open itself.
However, this algorithm may not yield a "lexicographically smallest" way to open the boxes.
The solve the problem, you should open the box with smallest number such that either this box is the last one of type i or there is still a way to get a type i key.

No comments:

Post a Comment