Solution for HKOI2010 Junior Q4 By Gary Sham
Problem Description Given 4 kinds of insects with different number and year of activity. Find the earliest year that can observe most insects. Bees = 2001, 2003, 2005 etc. Cicadae = 2002, 2005, 2008 etc. Beetles = 2001, 2002, 2005, 2006 etc. Butterflies = 2001, 2003, 2006, 2010 etc. E.g. { }, answer = 2017 is the earliest year that can see all insects.
Statistic #Attempts 46 #Maximum 100 #Maximum 5 #Mean (Attempted) 25.3 #Minimum 0 #Std Dev (Attempted) 32.5
Question How to know which kind of insects will appear that year? Mathematics Or simulation and array. Another question : When to stop??
Observation There are only 16 states of activity of insects. Save the result of all states? Do all states must appear at some time? The total number of insects must be the sum of them. If yes......
Solution1 year = 2010, Max = 0 While (true) do sum = 0 if (BEE && Cicadae && Beetles && Butterflies) sum+=BEE+Cicadae+Beetles+Butterflies; if (sum>max) output, break; Time Complexity: ??? Expected score: 50
In fact…… NO! The problem is Butterflies. Butterflies and Cicadae will not appear at the same time. Prove by Mathematics.
Full Solution For each state, there are only one answer: YEAR and HOW TO ADD THE NUMBER will not change. Hardcode We have to consider whether we choose Butterflies or Cicadae. Maximum 2021 Time Complexity: O(1) Expected Score: 100
Skills Observation Mathematics Hardcode
END