Solutions/Hints For The Problems: 1. Traffic Safe City (Points: 300)
Solutions/Hints For The Problems: 1. Traffic Safe City (Points: 300)
Solutions/Hints For The Problems: 1. Traffic Safe City (Points: 300)
w(a, k)/2.
Claim: There exists a violated set S with u S and v (V S) if and only if max ow in some H |V | 1. Proof Outline: Consider the capacity of the cut S and use the max-ow min-cut theorem. Using Edmond-Karp will clear upto 2nd test-case, however using Dinitz or any preow push based algorithm will clear all cases.
graph G generated above is planar and a lattice graph. Hence we can nd a valid orientation of G without actually computing the spanning tree and dual graph in O(V ). Then simply calculate the absolute value of the Pfaan (square root of the determinant) of the (1, 1, 0) adjacency matrix of G. [1] Y2K Problem of Dominoes and Tatami Carpeting from Puzzlers Tribute A Feast for the Mind [2] http://en.wikipedia.org/wiki/FKT algorithm [3] www.cs.bris.ac.uk/montanar/presentations/matchings.pdf
The following relation can be derived using a little mathematics. f (n) = 1 + (n + 1)f (n 1) 2n
You can successively compute the value in the form p/q using customised BIGINT datastructures and previously stored results. This reduces the complexity of calculation signicantly.
Similarly nd number of chords with (end > endM and start > startM and endM > start). The preprocessing with take O(N 2 ) time, and then each query of the M chords will take O(logN ) time, so total time is O(N 2 + M logN ). The naive approach takes O(M N ) time.
The problem boils down to the following statement: Given a set of rays parallel to y-axis and a point, does there exist a line through the point which intersects all the rays. Using dual plane transformations: Point (a, b) transforms to Line y = ax b. So, a line y = mx + c transforms to a point (m, c), and the rays get transformed into half planes. The problem gets transformed in the dual plane into: Given a set of half planes and a line, does there exist a point on the line which lies in each of the half planes. (i.e. does the line intersect the convex region formed by the intersection of the half planes) So to nd the convex region from the half planes: One way of doing this is to nd the dual plane of this plane, (the original plane). The intersection of the upper half planes is computed by computing the upper convex hull of corresponding points. Similarly intersection of lower half planes can be computed. Then their intersection is computed. This takes O(nlogn) time. Now we have set of points of the convex polygon (Convex open spaces are excluded according to the problem statement). We have to nd if the query line intersects the polygon. We have N points v0 , v1 , ... vN . Determine if the line (v0 , vn/2 ) intersects the query line.
Case 1: They do not intersect. In this case the line we are interested in is parallel and hence can intersect at most one half of the polygons v0 , v1 , ..., vn/2 and v0 , v(n/2) , ... vn . So we can recurse into that half of the polygon. Case 2: They do intersect. There are 3 sub-cases: Case 2.1 : The intersection is between the points v0 and vn/2 We are done. The line intersects the polygon. Case 2.2 : The intersection is closer to v0 (that is, outside the polygon on v0 s side). Determine if the query line intersects with the line (v0 , v1 ). If it does not then we are done, the line does not intersect the polygon. If it does, nd the intersection and let it be p. If p and v1 are on the same side of the line (v0 , vn/2 ) then recurse into the half of the polygon, v0 , v1 , ..., vn/2 , otherwise recurse to the half v0 , vn/2 , ... vn . Case 2.3 : The intersection is closer to vn/2 . Deal it as case 2.2. Each query takes log(n) time.