37
程序设计竞赛实训基地 Programming Contest Training Base The 2019 “Orz Panda” Cup Programming Contest Closing Ceremony Programming Contest Training Base Xidian University Aug. 21, 2019

The 2019 “Orz Panda” Cup Programming Contestacm.xidian.edu.cn/orz-panda/2019/editorial.pdf · T = O(n) Programming Contest Training Base Problem A APA of Orz Pandas Teams passed/tried:

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

  • 程序设计竞赛实训基地Programming Contest Training Base

    The 2019 “Orz Panda” Cup Programming ContestClosing Ceremony

    Programming Contest Training Base

    Xidian UniversityAug. 21, 2019

  • 程序设计竞赛实训基地Programming Contest Training Base

    Part IEditorial

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem AAPA of Orz Pandas

    ▶ Teams passed/tried: 1/4 (10 tries)

    ▶ Solution:▶ Parse the expression into a tree (using stack explicitly, or recursively)▶ LNR (in-order) traverse the tree and output▶ T = O(n)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem AAPA of Orz Pandas

    ▶ Teams passed/tried: 1/4 (10 tries)▶ Solution:

    ▶ Parse the expression into a tree (using stack explicitly, or recursively)▶ LNR (in-order) traverse the tree and output

    ▶ T = O(n)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem AAPA of Orz Pandas

    ▶ Teams passed/tried: 1/4 (10 tries)▶ Solution:

    ▶ Parse the expression into a tree (using stack explicitly, or recursively)▶ LNR (in-order) traverse the tree and output▶ T = O(n)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem BBrute Force of Orz Pandas

    ▶ Teams passed/tried: 15/20 (59 tries)

    ▶ Solution:▶ We only want one line so we can determine which branch we should

    recursively call▶ Compare k with 2n − 1▶ For n > 100, k < 263 < 2n − 1▶ Swapping another and to, and then swap back...▶ So for n > 100 we can reduce n to n − 2▶ For n = 102, 104, · · · , reduce to n = 100▶ For n = 101, 103, · · · , reduce to n = 99.▶ T = O(1)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem BBrute Force of Orz Pandas

    ▶ Teams passed/tried: 15/20 (59 tries)▶ Solution:

    ▶ We only want one line so we can determine which branch we shouldrecursively call

    ▶ Compare k with 2n − 1

    ▶ For n > 100, k < 263 < 2n − 1▶ Swapping another and to, and then swap back...▶ So for n > 100 we can reduce n to n − 2▶ For n = 102, 104, · · · , reduce to n = 100▶ For n = 101, 103, · · · , reduce to n = 99.▶ T = O(1)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem BBrute Force of Orz Pandas

    ▶ Teams passed/tried: 15/20 (59 tries)▶ Solution:

    ▶ We only want one line so we can determine which branch we shouldrecursively call

    ▶ Compare k with 2n − 1▶ For n > 100, k < 263 < 2n − 1▶ Swapping another and to, and then swap back...▶ So for n > 100 we can reduce n to n − 2▶ For n = 102, 104, · · · , reduce to n = 100▶ For n = 101, 103, · · · , reduce to n = 99.

    ▶ T = O(1)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem BBrute Force of Orz Pandas

    ▶ Teams passed/tried: 15/20 (59 tries)▶ Solution:

    ▶ We only want one line so we can determine which branch we shouldrecursively call

    ▶ Compare k with 2n − 1▶ For n > 100, k < 263 < 2n − 1▶ Swapping another and to, and then swap back...▶ So for n > 100 we can reduce n to n − 2▶ For n = 102, 104, · · · , reduce to n = 100▶ For n = 101, 103, · · · , reduce to n = 99.▶ T = O(1)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem CCai Xukun and Orz Pandas

    ▶ Teams passed/tried: 3/13 (55 tries)

    ▶ Solution:▶ It’s easy to see if Cai Xukun has a solution with a velocity v1, he can

    always find a solution for all v with |v| > |v1|▶ So we can always use the maximum velocity▶ Solve the parabola equation to get the answer

    v2t2 = x2 + (y + 12

    gt2)2

    ▶ Special case: t = 0▶ T = O(1)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem CCai Xukun and Orz Pandas

    ▶ Teams passed/tried: 3/13 (55 tries)▶ Solution:

    ▶ It’s easy to see if Cai Xukun has a solution with a velocity v1, he canalways find a solution for all v with |v| > |v1|

    ▶ So we can always use the maximum velocity▶ Solve the parabola equation to get the answer

    v2t2 = x2 + (y + 12

    gt2)2

    ▶ Special case: t = 0▶ T = O(1)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem DDirector of Orz Pandas

    ▶ Teams passed/tried: 5/9 (28 tries)

    ▶ Solution:▶ A classical minimum-cut problem▶ Use a maximum flow algorithm to solve it▶ T = O((n + m)2

    √k), using highest label push-relabel algorithm

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem DDirector of Orz Pandas

    ▶ Teams passed/tried: 5/9 (28 tries)▶ Solution:

    ▶ A classical minimum-cut problem▶ Use a maximum flow algorithm to solve it▶ T = O((n + m)2

    √k), using highest label push-relabel algorithm

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem EExpectation of Orz Pandas

    ▶ Teams passed/tried: 1/1 (3 tries)

    ▶ Solution:▶ The answer is (sum of all numbers in[l, r])/(number of stripes in[l, r])▶ Use a segment tree to maintain them▶ Use power series summary to maintain the labels in the tree▶ T = O(m log n)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem EExpectation of Orz Pandas

    ▶ Teams passed/tried: 1/1 (3 tries)▶ Solution:

    ▶ The answer is (sum of all numbers in[l, r])/(number of stripes in[l, r])▶ Use a segment tree to maintain them▶ Use power series summary to maintain the labels in the tree▶ T = O(m log n)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem FFullerene of Orz Pandas

    ▶ Teams passed/tried: 0/0

    ▶ Solution:▶ Try using Burnside’s lemma:

    |X/G| = 1|G|

    ∑g∈G

    c0(g) =1

    |G|∑g∈G

    ∑x∈X

    [g · x = x]

    ▶ What is G?

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem FFullerene of Orz Pandas

    ▶ Teams passed/tried: 0/0▶ Solution:▶ Try using Burnside’s lemma:

    |X/G| = 1|G|

    ∑g∈G

    c0(g) =1

    |G|∑g∈G

    ∑x∈X

    [g · x = x]

    ▶ What is G?

  • 程序设计竞赛实训基地Programming Contest Training Base Rotations in G

    ▶ 12× (C5 + C25)▶ 20× C3▶ 15× C2

  • 程序设计竞赛实训基地Programming Contest Training Base Counting c0

    ▶ Note that 5 is a prime, and there are no points on the C5 axis...

    ▶ We can see the C5 permutation can be divided into 12 5-cycles.▶ To make the coloring x unchanged with C5 operation, all points

    belonging to the same 5-cycle must have same color.▶ We can use 60/5 = 12 colors. So c0(C5) = n12.▶ Similarly, c0(C3) = n20, and c0(C2) = n30.

  • 程序设计竞赛实训基地Programming Contest Training Base Counting c0

    ▶ Note that 5 is a prime, and there are no points on the C5 axis...▶ We can see the C5 permutation can be divided into 12 5-cycles.▶ To make the coloring x unchanged with C5 operation, all points

    belonging to the same 5-cycle must have same color.▶ We can use 60/5 = 12 colors. So c0(C5) = n12.

    ▶ Similarly, c0(C3) = n20, and c0(C2) = n30.

  • 程序设计竞赛实训基地Programming Contest Training Base Counting c0

    ▶ Note that 5 is a prime, and there are no points on the C5 axis...▶ We can see the C5 permutation can be divided into 12 5-cycles.▶ To make the coloring x unchanged with C5 operation, all points

    belonging to the same 5-cycle must have same color.▶ We can use 60/5 = 12 colors. So c0(C5) = n12.▶ Similarly, c0(C3) = n20, and c0(C2) = n30.

  • 程序设计竞赛实训基地Programming Contest Training Base At last

    |X/G| = n60 + 12× 2× n12 + 20× n20 + 15× n30

    1 + 12× 2 + 20 + 15

    ▶ T = O(1) (or for lazy people T = O(log n), with a naive Pythonprogram)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem GGame of Orz Pandas

    ▶ Teams passed/tried: 1/1 (6 tries)▶ Use SG theorem at first, we just need to enumerate the ways to

    make the xor of all selected numbers is exactly x.▶ Then use Walsh transform. Then we only need to multiply the

    numbers, then do a reverse Walsh transform to get the answer.▶ Prefix product - just like prefix sum:∏r

    k=l Yk = prod(r) · prod(l − 1)−1.

  • 程序设计竞赛实训基地Programming Contest Training Base A special case

    ▶ Special case: Yk ≡ 0.

    ▶ We can check if there is an Yk ≡ 0 where k ∈ [l, r] using a prefixsum, and return 0 for these cases.

    ▶ Then we ignore the numbers ≡ 0 in prefix product, so they won’taffect other queries.

    ▶ We we do the reverse Walsh transform, since we only need y(x)instead of the entire y, we should use the naive algorithm (in O(P)),instead of O(P log P) FWT. (Q = max{pi, x}.)

    ▶ T = O(nP log P + QP) (with FWT preprocessing) orT = O(P2 + mP + QP) (with naive preprocessing)

  • 程序设计竞赛实训基地Programming Contest Training Base A special case

    ▶ Special case: Yk ≡ 0.▶ We can check if there is an Yk ≡ 0 where k ∈ [l, r] using a prefix

    sum, and return 0 for these cases.▶ Then we ignore the numbers ≡ 0 in prefix product, so they won’t

    affect other queries.▶ We we do the reverse Walsh transform, since we only need y(x)

    instead of the entire y, we should use the naive algorithm (in O(P)),instead of O(P log P) FWT. (Q = max{pi, x}.)

    ▶ T = O(nP log P + QP) (with FWT preprocessing) orT = O(P2 + mP + QP) (with naive preprocessing)

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem HHorton and Orz Pandas

    ▶ Teams passed/tried: 4/10 (77 tries)▶ At first notice this is a classical rational programming problem.▶ If the optimal solution is k0 = max{B(x)/A(x)}, then we can define

    F(x, k) = B(x)− k · A(x)

    ▶ With a given k, we can solve

    ∆(k) = maxx

    F(x, k)

    ▶ For optimal solution we have ∆(k0) = maxx F(x, k0) = 0▶ If k1 > k2,

    ∆(k1) = maxx F(x, k1) = F(xopt1 , k1)

    < F(xopt1 , k2) ≤ maxx F(x, k2) = ∆(k2)

  • 程序设计竞赛实训基地Programming Contest Training Base Binary search

    ▶ So ∆(k) is monotonic. Binary search to find k0.▶ How to evaluate ∆(k) = maxx F(x, k)?▶ Let the weight of the edges to be bi − k · ai, then use Prim’s

    algorithm!▶ Special case: for bi − k · ai > 0, we should always add this edge.

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem IIPv6 Address of Orz Pandas

    ▶ Teams tried/passed: 3/5 (19 tries)▶ Stupid problem (that means the problem setter is too stupid).▶ Use Python to convert this large integer to hexadecmial ("%x" %

    addr)▶ Then find the consecutive zeros with the number of sections as large

    as possible. Since the ASCII of : is larger than 0, if there aremultiple solutions choose the zeros near the tail of the string.

  • 程序设计竞赛实训基地Programming Contest Training Base

    Problem JJobless Orz Pandas

    ▶ Teams passed/tried: 1/1 (1 try)▶ The signed volumn is multiplied by a factor of |A| if the coordinates

    are transformed by matrix A.▶ So the answer is (|A|−1

    ∏bi)2.

  • 程序设计竞赛实训基地Programming Contest Training Base

    Part IIAwards

  • 程序设计竞赛实训基地Programming Contest Training Base Fastest to Solve

    ▶ Geometric Rhythm: Fastest to solve problem B, C, D, E, G, and J▶ Two old doges: Fastest to solve problem H▶ @21:30: Fastest to solve problem A▶ International group of qkoqhh: Fastest to solve problem I

  • 程序设计竞赛实训基地Programming Contest Training Base Bronze Medals

    ▶ KFC basketball team: 1/135▶ No team name: 1/124▶ Sakura tree: 1/105▶ Output illegal: 1/76

  • 程序设计竞赛实训基地Programming Contest Training Base Silver Medals

    ▶ Dawn: 2/361▶ WaAutomation: 2/263▶ International group of qkoqhh: 3/698▶ Oooooooor2: 3/607

  • 程序设计竞赛实训基地Programming Contest Training Base

    Gold Medal3rd Place

    @21:30: 4/1266▶ Team members: Xie Mingzhe, Hu Guangpeng, and Li Xuanzhe

  • 程序设计竞赛实训基地Programming Contest Training Base

    Gold Medal2nd Place

    Two old doges: 4/1767▶ Team members: Dai Yuquan, Li Hongzheng, and Chai Dongchen

  • 程序设计竞赛实训基地Programming Contest Training Base

    Gold MedalThe Champion

    Geometric Rhythm: 8/1734▶ Team members: Wang Xiaoqing, Wang Junyi, and Huang Haitong

  • 程序设计竞赛实训基地Programming Contest Training Base

    GL and HF!

    EditorialAPA of Orz PandasBrute Force of Orz PandasCai Xukun And Orz PandasDirector of Orz PandasExpectation of Orz PandasFullerene of Orz PandasGame of Orz PandasHorton and Orz PandasIPv6 Address of Orz PandasJobless Orz Pandas

    Awards