Songs HKOI 2012. Problem Description Dr. Jones wants to play the lowest key possible Musical notes are represented by positive integers Increasing the.

Slides:



Advertisements
Similar presentations
Complex Integrity Constraints in SQL. Constraints over a Single Table Table Constraint: Create TABLE Sailors (sid INTEGER, sname CHAR(10), rating INTEGER,
Advertisements

Problems and Their Classes
Searching for Data Relationship between searching and sorting Simple linear searching Linear searching of sorted data Searching for string or numeric data.
n-bit comparator using 1-bit comparator
Grade 8 Algebra I Identifying Quadratic Functions
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.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 9A Sorting (Concepts)
Dice HKOI 2012 Tony Wong. Hi! Tony Wong Year 4, Dual Degree Program in Technology and Management, HKUST (JA5309) BEng (Computer Engineering) & BBA (General.
If Statements & Relational Operators Programming.
1 Lecture 1: Course Overview Course: CSE 360 Instructor: Dr. Eric Torng TA: Huamin Chen.
Parallel Merging Advanced Algorithms & Data Structures Lecture Theme 15 Prof. Dr. Th. Ottmann Summer Semester 2006.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
7 = 7 SOLUTION EXAMPLE 1 Check the intersection point Use the graph to solve the system. Then check your solution algebraically. x + 2y = 7 Equation 1.
- ABHRA DASGUPTA Solving Adhoc and Math related problems.
Year Seven The Seven Ages of Man Learning Objectives
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
Graphical Solutions of a “Less Than” Linear Inequality in One Variable To determine the solutions of the inequality, graph the functions and. Sketch the.
WARM UP LINEAR EQUATIONS Solve the equation (Lesson 3.1, 3.4) 1.5(2x + 4) = 2(10 + 5x) 2.2x + 6(x + 1) = -2 3.
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall.
Notes Over 2.6 Checking Solutions of Inequalities Check whether the given ordered pairs are solutions of the inequality.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Solution to HW1. Problem 1 Need to find shortest path from a single source s to a single destination d. Have a condition in the Dijkstra algo loop which.
Functions Is Fibonacci Repeated or Recursive? Created by: Rachel Oakley.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 2.
Risk Analysis & Modelling
Starter A delegate comes to you (the receptions) and tell you they have lost their timetable (itinerary) What details would you ask them for to check the.
WARM UP MULTIPLE CHOICE Which function has an output of j=27 for an input of a = 3. (Lesson 1.8) a)j = 4a + 15 b)j = 15a + 4 c)j = 15 ∙ 4a d)j = 27a 3.
ALGORITHMS.
FINDING A POLYNOMIAL PASSING THROUGH A POINT. Review: the Linear Factorization Theorem If where n > 1 and a n ≠ 0 then Where c 1, c 2, … c n are complex.
Topics: Topic 1: Solving Linear Equations Topic 2: Solving Quadratic Equations Topic 3: Solving Proportions involving linear and quadratic functions. Topic.
Visual C++ Programming: Concepts and Projects Chapter 8A: Binary Search (Concepts)
Write a function rule for a graph EXAMPLE 3 Write a rule for the function represented by the graph. Identify the domain and the range of the function.
HKOI 2012 (Senior) Q4 - Gene Mutation Gary Wong For any question, please ask via MSN:
Lesson Menu Five-Minute Check (over Lesson 6-2) Then/Now New Vocabulary Key Concept:Invertible Square Linear Systems Example 1:Solve a 2 × 2 System Using.
Dr. Sajib Datta Feb 11,  Example of declaring and initializing an array. ◦ double someData[3]; /* declare the array someData that will.
4.3 Solving Systems of Linear Inequalities 11/7/12.
Dr. Sajib Datta Sep 10,  #include  void main()  {  int a = 25;  int b = 0;  int c = -35;  if( a || b ) ◦ printf("Test1\n");  else.
Lesson 4-1 Solving linear system of equations by graphing
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Solving Absolute Value Equations
Complex integers? Here a and b are integers.
Identifying quadratic functions
Evaluate the expression ( i) + ( i) and write the result in the form a + bi. Choose the answer from the following: i i i.
Lesson 5-1 Solving Systems by Graphing
Solve a system of linear equation in two variables
Lesson 7-4 part 2 Solving Systems by Elimination
KnighT’s Charge 8/26/15 A. Complete the “Victory Lap”.
HKOI 2005 Intermediate Training
Computer Science 2 Review the Bubble Sort
Insertion Sort Quiz on Thursday.
Multiplicative Inverses of Matrices and Matrix Equations
Computer Science 2 Getting an unknown # of …. Into an array.
Discrete Mathematics CS 2610
Solving Equations involving Decimal Coefficients
CSCE 222 Discrete Structures for Computing
Objectives Identify solutions of linear equations in two variables.
P.O.D. # 32 2/4/19.
Bellwork 1) Multiply. 3) Find the determinant. 2) Multiply.
Pod # 32 February 6, 2019.
Graph Review Skills Needed Identify the relationship in the graph
Review Tasks CLU 3MR Lesson 6.
Algorithms For use in Unit 2 Exam.
Applied Statistical and Optimization Models
Presentation transcript:

Songs HKOI 2012

Problem Description Dr. Jones wants to play the lowest key possible Musical notes are represented by positive integers Increasing the key of the song by x means that all notes of the song are increased by x.

Example Key = 0

Example Key = 1

Constraints In test cases worth 20% ▫1 ≤ A, B ≤ 100 In test cases worth 50% ▫1 ≤ A, B ≤ 3000 ▫A ≤ N ≤ 3000 In all test cases, ▫1 ≤ A,B ≤ 3000 ▫A ≤ N ≤ 1,000,000 Both lists are sorted in ascending order The highest note that the instrument can play is not greater than 2N.

Solution 1: Loop the answer We start from K = 0 -> 2N For each note in A ▫Find corresponding note A[i] + K in B ▫Linear Search --- O(B) If all notes can be played, output K Time complexity: O(NAB)

Solution 1a: Loop the answer Improved We start from K = 0 -> 2N For each note in A ▫Check whether corresponding note A[i] + K in B ▫O(1) If all notes can be played, output K Time complexity: O(NA) 3000 x 1,000,000

Solution 2: Loop the song It is mentioned in the task that the song starts with 1. To be able the play that note, the choice of keys (answers) are limited. That means the answers can only be one of B[i]-1

Solution 2: Loop the song For each K = B[i]-1 For each note in A ▫Check whether corresponding note A[i] + K in B ▫O(1) If all notes can be played, output K Time complexity: O(AB) 3000 x 3,000

Solution 1b: Loop the answer Improved!! We start from K = 0 -> 2N For each note in A ▫Check whether corresponding note A[i] + K in B ▫O(1) ▫If not, break If all notes can be played, output K Time complexity: O(N + A 2 ) 1,000, x 3,000