northern subregional contest acm icpc 2015−2016,...
Post on 08-Mar-2021
16 Views
Preview:
TRANSCRIPT
Northern Subregional ContestACM ICPC 2015−2016, NEERC
Problem Analysis
2Георгий Корнеев
Alex Origami SquaresProblem A
3Георгий Корнеев
Problem statement
Given a rectangle h by wCut 3 equal maximum squares
ACM ICPC NEERC Northern Subregion 2015-2016 / Problem analysis
4Георгий Корнеев
Solution
max( min / 2.0, // Case 1 min( max / 3.0,// Case 2 min, // Case 3 ))
ACM ICPC NEERC Northern Subregion 2015-2016 / Problem analysis
5Георгий Корнеев
Black and White Problem B
6Георгий Корнеев
Problem statement
Build a black and white grid B black regions черных областей W white regions Regions are 4-connected
ACM ICPC NEERC Northern Subregion 2015-2016 / Problem analysis
7Георгий Корнеев
Problem analysis
This construction works
ACM ICPC NEERC Northern Subregion 2015-2016 / Problem analysis
8Георгий Корнеев
ConcatenationProblem C
9Георгий Корнеев
Problem statement
Calculate the number of strings Formed by a concatenation of Nonempty prefix of S1 Nonempty suffix of S2
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
10Георгий Корнеев
Solution idea
When duplicates happen? Same letter in 2 strings
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
11Георгий Корнеев
Solution
Calculate the frequencies
C1i – frequency of i in S1
C2i – frequency of i in S2
Answer is
Look out for int overflowACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
12Георгий Корнеев
Distribution in MetagoniaProblem D
13Георгий Корнеев
Problem statement
Represent N as sum of terms 2a3b
Any number shouldn't be divisible by other
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
14Георгий Корнеев
Solution
For even n Solve for n/2 Multiply everything by 2
For odd n Solve for n – 3b, where b is max
possible Add 3b to the result
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
15Георгий Корнеев
Easy ArithmeticProblem E
16Георгий Корнеев
Problem statement
Add plus and minus signs to expression Maximize the result
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
⇓
17Георгий Корнеев
+d1d
2...d
k → leave as is
-d1d
2...d
k → transform into -d
1+d
2...d
k
Except for d2=0
-d1+0+d
3...d
k
Solution
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
18Георгий Корнеев
FygonProblem F
Георгий КорнеевПавел МавринПавел Маврин
Автор:Условие:
Тесты:
19Георгий Корнеев
Problem statement
Calculate the number of lag calls Output as polynomial of n For-loops
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
for i in range(n): for j in range(i): for x in range(5): laglag
20Георгий Корнеев
Solution
Polynomial's degree Equal to the number of nested loops Less than or equal to 6
Answer Interpret for n=0,1,…6 Use interpolation formulas
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
21Георгий Корнеев
GraphProblem G
22Георгий Корнеев
Problem statement
Given a DAGAdd at most k edges Maximize minimum possible
topological sort
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
23Георгий Корнеев
Solution
Construct a lex-min topological sortYou can add a vertex when: No incoming edges Choose minimum of those
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
24Георгий Корнеев
Inserting new edges
Many possible vertices Add edge leading to minimal vertex
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
25Георгий Корнеев
Inserting new edges
Single candidate remaining ? < d print and remove d⇒ ? > d insert new edge to ? from last ⇒
vertex in the output
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
26Георгий Корнеев
Implementation
Vertex In/out degree Remove an edge in O(1)
Ordered set
Candidates
Vertices with an edge
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
27Георгий Корнеев
Hash Code HackerProblem H
28Георгий Корнеев
Problem statement
Generate n strings with equal hash codes
Polynomial hash
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
29Георгий Корнеев
Solution
From sample output hash(ed) = hash(fe) = h
Construct 4 stringshash(eded) = hash(edfe) =
hash(feed) = hash(fefe) = (312 + 1)h
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
30Георгий Корнеев
Insider’s Information Problem I
31Георгий Корнеев
Problem statement
Unknown order M triples a
i < b
i < c
i
– Or ai > b
i > c
i
Find any arrangement Satisfying at least m/2 triples
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
32Георгий Корнеев
Solution
Triples correspond to some “real” order Some x is never in the middle
Save all triples with ai = x or c
i = x
Throw x away and solve recursively
Set x to minimum or maximum of all Saved triples determine which one Choose the majority
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
33Георгий Корнеев
Journey to the“The World’s Start”
Problem J
34Георгий Корнеев
Problem statement
Go from one metro station to another Maximum time T Re-entering takes some time
Travel cards allowing to travel r stations Find the cheapest one
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
35Георгий Корнеев
Solution
Binary search on rFind the minimum time to reach finish Dynamic programming
Ti = d
i + min
i-r'≤j<i T
j
Can be done in O(n) using queue with minimum
O(n log2n) is also accepted
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
36Георгий Корнеев
Kingdom TripProblem K
37Георгий Корнеев
Problem statement
«Straighten» the path Distance from the new path to old
vertices
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
38Георгий Корнеев
Allowed ray position
One point
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
39Георгий Корнеев
Allowed ray position
Many points
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
40Георгий Корнеев
Solution
Iterate over all starting points Iterate over all ending points Intersect all angles
Ending vertex is good if lies in the angle
After that, do a DP in O(n2)
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
41Георгий Корнеев
Lucky ChancesProblem L
42Георгий Корнеев
Problem statement
Given a matrix of numbersFind For each element For each direction If this element is strictly greater than all
numbers in this direction
ACM ICPC NEERC Northern Subregion 2015-2016 / Разбор задач
top related