HKOI 2005 Junior Q1 Pattern Matching ( 模式匹配 ). Question Given a target value (Sum of pattern P), find a sub-block with size equal to P having sum closest.

Slides:



Advertisements
Similar presentations
Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
Advertisements

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.
Lecture 4 More Examples of Karnaugh Map. Logic Reduction Using Karnaugh Map Create an Equivalent Karnaugh Map Each circle must be around a power of two.
Slide 1 of 52  Worked Examples Follows:. Slide 2 of 52.
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
Chapter 2 Section 3 Arithmetic Operations on Matrices.
ANGLES IN TRIANGLES LESSON 16(3).
X-box Factoring. Step 1: Set up X- Box Factor ax 2 + bx + c Product a  c Sum b.
Residuals and Residual Plots Most likely a linear regression will not fit the data perfectly. The residual (e) for each data point is the ________________________.
Jackson Structured Diagrams
Box Method for Factoring Factoring expressions in the form of.
100 Solve 3 X 7 = ? using base 10 blocks Build a 3 X 7 array! X.
Духовні символи Голосіївського району
Excel Part 2 Beth McKelvey. AutoSum The function in Excel that calculates the sum of a group of numbers.
What is Matrix Multiplication? Matrix multiplication is the process of multiplying two matrices together to get another matrix. It differs from scalar.
Adding Two and Three Digit Numbers
Section – Operations with Matrices No Calculator By the end of this lesson you should be able to: Write a matrix and identify its order Determine.
Excel Tips and Tricks Leda Voigt Green River College.
$200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200 $400 $600 $800 $1000 $200.
♣Multiplying Decimals♣
distance prediction observed y value predicted value zero
Box Method for Factoring
Box Method for Factoring
A SMALL TRUTH TO MAKE LIFE 100%
5Th Class Maths Additon & Subtraction.
Partial Products Algorithm for Multiplication
Block LU Decomposition: explained
A SMALL TRUTH TO MAKE LIFE 100%
A SMALL TRUTH TO MAKE LIFE 100%
Structured Query Language – The Fundamentals
1.4 Solving Absolute-Value Equations
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
mr-mathematics.com Recapping: Top heavy fractions and mixed numbers
A SMALL TRUTH TO MAKE LIFE 100%
13.9 Day 2 Least Squares Regression
A SMALL TRUTH TO MAKE LIFE 100%
Unit 3 Review (Calculator)
A SMALL TRUTH TO MAKE LIFE 100%
1.4 Solving Absolute-Value Equations
A SMALL TRUTH TO MAKE LIFE 100%
A SMALL TRUTH TO MAKE LIFE 100%
Building Complex Behaviors: Actions and States
Calculate 9 x 81 = x 3 3 x 3 x 3 x 3 3 x 3 x 3 x 3 x 3 x 3 x =
Digital Radio SoC Lab 2004 Spring Bit Engineering Lab., SITI.
Presentation transcript:

HKOI 2005 Junior Q1 Pattern Matching ( 模式匹配 )

Question Given a target value (Sum of pattern P), find a sub-block with size equal to P having sum closest to the target value

Partial Solution Use 4 For-loop to calculate the sum of each sub-block. For “Top” from 1 to (M – N + 1) For “Left” from 1 to (M – N + 1) Calculate Sum of Sub-Block(Top, Left) If Sum < MinSum Update Complexity: O(M²  N²)

Characteristic Two adjacent sub-block is overlap! Can we make use of this characteristic? Sum of Sub-Block(x, y) = Sum of Sub-Block(x – 1, y) - Sum of Column(1) of Sub-Block(x – 1, y) + Sum of Column(N) of Sub-Block(x, y) Improve a little bit only x-1, y x, y

Further Improvement Define a array SumFromTopLeft SumFromTopLeft(x, y) means the sum from Top-Left (1, 1) to (x, y) SumFromTopLeft(0, y) = 0 SumFromTopLeft(x, 0) = 0 SumFromTopLeft(x, y) = SumFromTopLeft(x, y - 1) + SumFromTopLeft(x - 1, y) - SumFromTopLeft(x - 1, y - 1) + PixelValue(x, y)

Con’t Sum of Sub-Block(x, y) x,y  M – N + 1 = SumFromTopLeft(x + N - 1, y + N - 1) - SumFromTopLeft(x, y + N - 1) - SumFromTopLeft(x + N - 1, y) + SumFromTopLeft(x, y) Complexity: O(M²)