hkoi programming
DESCRIPTION
HKOI Programming. HKOI Training Team (Intermediate) 2004-01-31. What you should learn from this lesson. How to solve a problem How to code faster How to test your program How to score more. Today’s flow. Competition Rules Problem Solving Coding Testing Tricks. Competition Rules. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/1.jpg)
HKOI Programming
HKOI Training Team (Intermediate)2004-01-31
![Page 2: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/2.jpg)
What you should learn from this lesson
How to solve a problem How to code faster How to test your program How to score more
![Page 3: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/3.jpg)
Today’s flow
Competition Rules Problem Solving Coding Testing Tricks
![Page 4: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/4.jpg)
Competition Rules
The winner is determined by– Fastest program?– Amount of time used in coding?– Number of tasks solved?– Highest score
![Page 5: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/5.jpg)
Scoring
Black-box Testing Marks will be given if a program passes a
certain test case A test case is passed if the output
– matches the expected one, or– satisfies certain criteria
No referral to source code
![Page 6: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/6.jpg)
The “OI” Programming Process
Reading the problem Thinking Coding Testing Finalizing the program
![Page 7: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/7.jpg)
Reading the problem
Usually, a task consists of– Title– Problem Description– Constraints– Input/Output Specification– Sample Input/Output– Scoring
![Page 8: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/8.jpg)
Reading the problem
Constraints– Range of variables– Execution time
NEVER make assumptions yourself– Ask whenever you are confused
Read EVERY word Make sure you understand before going on
![Page 9: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/9.jpg)
Thinking
Classify the problem– Graph? Mathematics? Data Processing? …
Compare with some past problems– Any similarity?
For complex problems, divide the problem into smaller sub-problems
![Page 10: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/10.jpg)
Thinking
Draw diagrams Consider special cases Is the problem too simple?
– Be suspicious, you may have overlooked something
Still no idea? Give it up… Try again later
![Page 11: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/11.jpg)
Designing the solution
Some points to consider– Execution Time (Time Complexity)– Amount of memory used (Space Complexity)– How to store data? (Data Structure)– Difficulty in coding
![Page 12: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/12.jpg)
Coding
Coding is just a small part in the competition Less coding time means more time for
thinking (which is more important) FYI, usually I complete a program in 15
minutes How to reduce code faster?
![Page 13: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/13.jpg)
Characteristics of OI programs
Simple Input/Output Assumption: Data input format always
matches specification Short programs (usually < 100 lines)
![Page 14: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/14.jpg)
Common practices in OI-coding
No comments needed Short variable names (usually 1-2 chars) Less procedures / functions Use of break, continue and goto Hardcoding (Not recommended)
![Page 15: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/15.jpg)
Common practices in OI-coding
Use a slightly larger array than needed Pascal users: use longInt instead of integer
Avoid real numbers (sometimes not possible) Avoid long and complex expressions Save and Compile frequently
![Page 16: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/16.jpg)
Testing
Sample Input/Output “A problem has sample output for two
reasons:1. To make you understand what the correct output
format is2. To make you believe that your incorrect solution
has solved the problem correctly ”
![Page 17: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/17.jpg)
Testing
Create some simple input yourself (by hand) Boundary cases “Large” input
– Test for execution time and integer overflow Tricky cases
![Page 18: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/18.jpg)
Debugging
Print values of important variables to screen and/or files
Print messages to screen and/or files Use debugger
– FreePascal IDE debugger– GDB
![Page 19: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/19.jpg)
Finalizing
Check I/O filename Check output format
– Any trailing spaces? Correct source/executable name? Is the executable updated?
![Page 20: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/20.jpg)
Tricks
Quick and dirty ways to get marks Usually, 10-20% of total marks are allocated
to simple test cases Write programs that handles these cases
ONLY Use only when you have totally no idea on a
task or time is running out
![Page 21: HKOI Programming](https://reader035.vdocuments.mx/reader035/viewer/2022062302/56815511550346895dc2f415/html5/thumbnails/21.jpg)
Tricks
“No solution” Sample Input/Output Special cases Hardcoding Stop the program before execution time runs
out