SlideShare a Scribd company logo
1 of 81
An awareness program on
ACM –ICPC( Programming
Competition)
A Briefing Session 1
Prof NB Venkateswarlu,
B.Tech, M.Tech(IIT-K), PhD(BITS, Pilani), PDF(U of Leeds, UK)
AITAM, Tekkali
10th
March 2015
9.30AM
2
What is ACM?
 Internationally, ACM stands for
Association of Computing Machinery
About ACM
ACM, the Association for Computing Machinery
www.acm.org, is the world’s largest
educational and scientific computing society,
uniting computing educators, researchers and
professionals to inspire dialogue, share
resources and address the field’s challenges.
ACM strengthens the computing profession’s
collective voice through strong leadership,
promotion of the highest standards, and
recognition of technical excellence. ACM
supports the professional growth of its
members by providing opportunities for life-long
learning, career development, and professional
networking.
International Collegiate
Programming Contest (ICPC)
World renowned
programming competition.
Regionals  World Finals
Other Programming
Competitions
International Olympiad in
Informatics
http://www.ioinformatics.org
Microsoft Imagine Cup
https://www.imaginecup.com
8
Annual Code Match (ACM)
 We borrowed the acronym 'ACM' and made it
Annual Code Match
 The IBM-Annual Code Match 2006 & 2007
– Modelled after ACM-ICPC, but held at university-level,
closed doors
– Sponsored by IBM Malaysia
– http://fit.mmu.edu.my/codematch
 The winning teams were sponsored to ACM-
ICPC Asia Regionals in Manila (Oct 2006) and
Singapore (Dec 2007)!
www.challenge24.org
Where are you great India, so
called the mighty IT Giant?
13
Why take part in competitions?
 Develop your problem-solving skills
 To break Google, FB, Yahoo, Amazon Interviews and
earn 1.7Cr package and gloom in News Papers and
bring fame to your parents, and to your college,
 To win some cash $$ or prizes. 
 An opportunity to represent the university in various
competitions if selected
 …and normally that's fully sponsored!
 It’s where you can demonstrate what you are really
capable of
 Learn to compete seriously!
 Good for your CV?
14
Why this two day course is
organized?
 Find the cream of the crop...to represent your
Institute in future competitions (Especially ACM-
ICPC)
 Develop a problem-solving 'culture' among our
students
 Provide the talented students a platform to
increase their potentials (forget about the
classroom...)
 Stone sharpens stone
 ALSO TO KNOW YOUR INTEREST TO
CONTINUE THIS ACTIVITY.
How I am qualified for the
delivery of this two day
course?
My Books
http://www.amazon.com/dp/
B00T1OK42K
http://www.amazon.com/dp/
B00RFDZT2E
20
ACM Rules…briefly
21
ACM Rules
 Languages: C, C++, Java
 Each team will be provided with 1 computer
usually with Linux
 Allowed to bring in 25 pages of notes
 Contest will be run for 5 hours
– Food and drinks will be normally provided
 Number of questions: 7-10
 Contest is conducted using PC2
system
– Submission of answers
– Clarification
– Judging (human and/or computer judge)
– Live scoreboard
22
Scoring System
 Solutions to problems submitted are called runs.
 Teams are ranked according to most problems
solved
 Teams that solve the same number of problems
are ranked by
– Least total time
– Earliest time of submittal of last accepted run
23
Scoring System
 Total time = Sum of time consumed for each
problem
 Time consumed = Time elapsed from beginning
of contest to submittal of accepted run
 Each rejected run: +20 penalty minutes
 No time is consumed for an unsolved problem
 Output must be exactly same as required
format, otherwise considered wrong!
24
Sample Scoreboard
2006 ACM Final Scoreboard
Submitting
• You will receive one of several responses:
– Format error
– Time limit reached
– Runtime error (division by 0, out of memory,
exception thrown, etc.)
– Compile error
– Wrong answer
– Correct!
• The judges only give you one at a time
– If you have two or more problems, you’ll usually
only get the more embarrassing of them
Always have someone typing
• Typing and compiling is time intensive, and
there’s only one keyboard
– If your program isn’t working, print it and debug
it by hand
– Let someone else sit and type!
• If you’re waiting for the computer, write
some code out by hand or ask a neighbor
for their opinion on your algorithm
• If it has you read until end of input, use:
while (cin >> x)
Questions
 You can submit questions to the judges
about problems
 Updates will be given to everyone if
there is a typo or other error
 You will get one of two responses:
– A clarification
– No answer (i.e. read the problem more
closely)
Test the judge’s input
 They give you 1 or 2 sample inputs and
solutions; test them!
– There will normally be simple cases.
 Make sure your format exactly matches
the judge’s sample output!
– They use a file compare (via a script) so it
must be very close
End cases
 The judges are very tricky with their tests
 If the problem says inputs will be
between A and B, you can almost bet
that inputs of size A and B will be tested
 Be wary of carefully worded questions!
30
Typical ACM Problem Format
(1) Problem description
(2) Input description
(3) Output description
(4) Sample input
(5) Sample output
31
Standard I/O technique
 Input stream has to be continuously inputted
with data (number, char, string, etc.) until it
finishes.
 Output will show all that has been processed.
 May not be the best way to test your codes, but
it is required for submission.
 Use Input File Piping technique for easier
testing & debugging of data
32
Sample Problem
 Finding the absolute difference between 2
numbers
 Demo
– Standard “continuous” I/O (for submission of solution)
– Input File Piping (for testing/debugging)
Sample Input:
3 7
2 -2
Sample Output:
4
4
33
File Reading – Not often
 Possibly need to do file reading if the problems
require you to specifically use a certain name of
input text file such as “data.txt”, but this is rare.
34
(PC)2
Submission System
 Software for teams to submit their answers for
evaluation. Result feedback (Accepted or
Rejected with specific reason) is quite fast.
 Software allows teams to test (compile and run)
their answers with the server environment.
 Answers are evaluated with judges' own set of
test data
Some Important Concepts
 Backtracking
 Complete Search
 Dynamic Programming
 Encryption
 Game/Puzzle
 Chess
 Sudoku
 Graph Theory
 Greedy
 Mathematical
Some Important Concepts
 Bases
 General
 Geometry
 Perfect Squares
 Physics
 Parsing
 Straightforward
 Tree
Be generous with your
memory!
 Make your arrays twice as big as
necessary
– Off by one error are difficult to find!
 Use the STL (strings, vectors,
everything!)
 Use long long instead of int
 Use double instead of float
Code quickly at the cost of
efficiency
 The faster you type, the faster you
submit!
 Use the STL if it makes it easier for you
– If you can’t remember how to use the STL
sort, write a simple (bubble?)sort. Who
cares!
 Generally, if you get a “time limit
reached”, your algorithm needs to be
changed, not just little things in your
code
Helpful suggestion
 Bring printed code, such as the
algorithms we’ll talk about.
• You won’t have to remember them and know
you have a working/correct version too.
– If someone is not typing in an answer, type
in the algorithm so the template is ready to
use.
– Also data structures you may want to use
(trees for example).
– Including a “read a file” code. You know it
works, then one least thing to think about.
math
 Number theory
– Very popular in the program contests
– For ICPC, you need a rather small but
useful set
• Prime table generation, primality testing,
greatest common divisor, modular arithmetic
and congruence (solving linear congruences),
and Euler’s
– A Note, Java’s BigInteger class has a
number of number-theoretic functions, like
gcd, modular exponentiation, primality
testing, etc.
String manipulation
 There have been a number of string
manipulation questions over the years.
 Learn the string library
– At the least substring, replace, find etc.
– Regex maybe really helpful.
algorithms
 Brute force algorithms
– From nested loop algorithms to backtracking
(easier with recursion).
• Breath first search.
• Depth first search is recursive and has nice
bracktracking features.
 Dynamic Programming
– Recursive algorithm that is composed of
subproblems
• Coin flipping and fibonacci are simple examples
• Longest Common Subsequence (LCS), Longest
Increasing Subsequence (LIS), Optimal Binary
Search tree (OBST), 0-1 knapsack, edit distance,
Matrix Chain Product are increasing harder
examples.
algorithms
 Trees and priority queues, not necessary
an algorithms, but can speed things up.
 Graph theory
– How to represent things and then use BFS
and DFS, and topological sorting.
• Does the graph have cycles?
Classic Problems algorithms
 Shortest paths (Dijkstra for example)
 Spanning trees (Prim or Kruskal)
 Eulerain paths and circuits
 Matchings in bipartite graphs
 Network flow (max flow, min cost flows)
 Geometry.
STL: Deque
 #include <deque>
 deque<int> x;
 x.push_back(20); x.pop_back(); x.back();
x.push_front(20); x.pop_front(); x.front();
 x.resize(100);
 x[10] OR x.at(10);
 x.clear();
STL: Strings
• #include <string>
• string str; string str(“foo”); string str(10, ‘c’);
• str += “bar”;
• Find
– str.find(“aaba”); str.rfind(“aaba”);
– str.find_first_of(“AEIOU”);
– str.find_last_not_of(“AEIOU”, 5);
– Returns an int, or string::npos if none found
• str.substr(int position, int length)
STL: Algorithms
• #include <algorithm>
• swap(a, b); // Any type that has = can go here!
• reverse(arr, arr + 10);
reverse(deq.begin(), deq.end());
• Sorting
– sort(arr, arr + 10); sort(deq.begin(), deq.end());
– sort(arr, arr + 10, lessThanFunction);
bool lessThanFunction(const Type& t1, const
Type& t2)
{
if (t1 < t2)
return true;
return false;
}
STL: Algorithms
 #include <algorithm>
 Permutations
int x[] = {3, 5, 4, 1, 2};
sort(x, x + 5);
do {
// stuff
} while (next_permutation(x, x + 5));
STL: formatting
• #include <iomanip>
• double d = 12345.6789;
• cout << d << endl;
• cout << setprecision(3) << d << endl;
• cout << setprecision(3) << fixed << d << endl;
• cout << setprecision(1) << fixed << 0.55 <<
endl;
• int i = 42;
• cout << hex << i << endl;
• cout << hex << uppercase << i << endl;
• cout << i << endl;
• cout << dec << i << endl;
• 12345.7
• 1.23e+04
• 12345.679
• 0.6
• 2a
• 2A
• 2A
• 42
Algorithms
 Brush up on
– depth-first search, breadth-first search (or just
use iterative deepening DFS)
• N-Trees, but lots of other uses as well.
 minimum spanning trees
http://en.wikipedia.org/wiki/Minimum_span
ning_tree
– Lots of varying algorithms
listed at the bottom of the page
Algorithms (2)
 shortest path, like Dijkstra’s algorithm
– http://en.wikipedia.org/wiki/Dijkstra’s_algorit
hm
– http://en.wikipedia.org/wiki/Shortest_path_pr
oblem
 (Max) flow problems
– http://www-b2.is.tokushima-
u.ac.jp/~ikeda/suuri/maxflow/Maxflow.shtml
• Good demo of max flow and min cut algorithms.
• Also links to some other versions of spanning
tree algorithms.
Algorithms (3)
 Greatest common divisor is a fun one to
remember too
– And remember, if gcd(a, b) == 1, then a and
b are relatively prime!
Dynamic
programming/memoization
• Recursive algorithm that is composed of
subproblems
– You keep recomputing the subproblems!
– Save them in an array and look them up
– Start with the recursive version first, then
modify it to save work
• Examples
– Fibonacci
– Coin problem
Geometric algorithms
Geometric algorithms
 Intersection
– Four points: a1, a2, b1, b2
– Compute:
• dir1 = direction(b1, b2, a1)
• dir2 = direction(b1, b2, a2)
• dir3 = direction(a1, a2, b1)
• dir4 = direction(a1, a2, b2)
– If dir1/dir2 are opposite signs, and dir3/dir4
are opposite signs, they intersect
a1
a2
b1
b2
dir
1
dir
2
dir
3
dir
4
a1
a2
b1
b2
dir
1
dir
2
dir
3
dir
4
57
Debunking some myths
 I know C, C++, C#, Java, Pascal, Perl, Python,
LISP,… I don’t think I have much problem with
programming!
 Good in programming == Good in problem solving
 Look, I know how to solve this problem on paper!
In ACM, programming is just a tool
Can you code it?
!=
Here, we want to solve problems, not write nice programs
 I can write a really nice program, with neat
functions and classes you know!
Some Important Difficulties
of students. Most students do not perform well under limited time
pressure. This hinders their performance not only in
programming competitions, but also in employment
interviews that focus on immediate problem solving.
 Students have difficulty with the analysis of new
problems and being able to select an appropriate
algorithm.
 Students often have difficulty expressing their point of
view on how a problem should be solved. They might
lack confidence or communication skills, or they may
not have experience in explaining the workings of an
algorithm.
 Students at the Junior year level have had little or no
exposure to teamwork in a problem solving context.
Some useful online judging
sites
 www.spoj.com
 www.wcipeg.com
 http://acm.pku.edu.cn/JudgeOnline/
 icpcres.ecs.baylor.edu/onlinejudge
 www.iarcs.org.in
 https://www.hackerrank.com
 https://www.hackerrank.com
60
Useful Resources
 “Programming Challenges: The Programming Contest
Training Manual” by Steven Skiena & Miguel Revilla
– http://fit.mmu.edu.my/codematch/acm_downloads.php
 UVA Problemset Archive – favourite spot for people to
train for ACM contests
– http://uva.onlinejudge.org/
– PLEASE register an account and try out the problems! 
 ACM-ICPC Live Archive – past year regional/world final
questions
– http://acmicpc-live-archive.uva.es/nuevoportal/
Dictionary of Algorithms and
Data Structures maintained
by NIST
 http://www.nist.gov/dads
Skiena Steven, Stony Brook
Algorithm Repository,
 http://www.cs.sunysb.edu/~algorith
63
The “Guidebook”
 Data Structures
 Strings
 Sorting
 Arithmetic
 Combinatorics
 Number Theory
 Backtracking
 Graph Traversal
 Graph Algorithms
 Dynamic Programming
 Grids
 Geometry
 Computational Geometry
64
Some things to kickstart…
 Register in mmu-acm Google Group – for
communication, discussion, sharing
– http://groups.google.com/group/mmu-acm
– Invitation will be sent out soon…
 You may work closely with people whom you’re
comfortable with. Teamwork can be forged early.
 Continue to sharpen your programming skills
 Learn useful algorithms for problem-solving
65
Questions?
66
Session 2
OK, we are going to try some
very simple problems! 
Counting characters in a
range
• Input will consist of two integers, 0 < N <
100
• For each of the numbers in between these
two numbers (inclusive), count the
occurrences of each digit
• Example: 17 21
– 17 18 19 20 21
– 0=>1 7=>1
1=>4 8=>1
2=>2 9=>1
Counting characters in a
range
• cin >> a >> b;
for (i = a; i <= b; ++i)
{
++arr[i / 10];
++arr[i % 10];
}
• 17 21 ?
• 21 17 ?
Problem #1
 If you have a one-dimensional array of
unsorted number such as
0, 9, 3, 15, 4, 11, 25, 3, 0
 Convert it into a two-dimensional array
whose numbers of row and column are
equal, such that the largest element is at
the top left corner, and continue to put the
next largest element in-ward in a clock-
wise manner
25 15 11
0 0 9
3 3 4
Solution to HW Problem #1
1. Let input_size = the size of input array
2. table_size = ceil(sqrt(input_size))
– Note that ceil() is the function that rounds
the input number to the nearest integer
greater than the input number
– sqrt() is the square root function.
1. Sort input array (from smallest value to
largest value)
i. Create an empty array of input_size and
name it temp
ii. Set value index = 0
iii. Find the smallest value in input array and
put it in temp[index]
iv. Replace the smallest value with ∞
v. index = index + 1
vi. Repeat from iii to vi until index ==
input_size
4. Create 2-dimensional array of
table_size*table_size named
output_array
Solution to HW Problem #1 (ii)
5. Set index_row = index_column = 0,
index = input_size-1
6. do
7. output_array[index_row][index_column]
= temp[index]
8. [index_row, index_column] = next(index,
input_size, table_size)
9. index = index – 1;
10. While index >= 0
11. Return output_array
Solution to HW Problem #1 (iii)
Subroutine next(index, index_row, index_col,
input_size, table_size)
1. track_dex = input_size – index -1
2. If track_dex < 4(table_size-1)
if track_dex < table_size
return [index_row, index_col +1]
else if track_dex < 2*table_size – 1
return [index_row+1, index_col]
else if track_dex < 3*table_size – 2
return [index_row, index_col-1]
else
return [index_row – 1, index_col]
1. Else
return next(index-4(table_size-1),index_row,
index_col, input_size – 4(table_size-
1),table_size – 2);
Session 3
 Programming Examples Continued
Session 4 – Recapitulation of
Mathematics
Session – 5
Recapitulation of Data
Structures
Session 6
Some More Puzzles
Session 7
Some More Puzzles
Session 8
Some More Puzzles
Any Questions
Thanks
 To you
 The Management
 The Principal
 Head, Dr Srinivasarao Garu
 Mr. Mahesh

More Related Content

What's hot

What's hot (10)

CANADA Student Visa Process
CANADA Student Visa ProcessCANADA Student Visa Process
CANADA Student Visa Process
 
All About IIT JEE You Must Know
All About IIT JEE You Must KnowAll About IIT JEE You Must Know
All About IIT JEE You Must Know
 
Indian students studying abroad
Indian students studying abroadIndian students studying abroad
Indian students studying abroad
 
Study in Canada
Study in CanadaStudy in Canada
Study in Canada
 
Admission Strategy-May-26-2022 final.pptx
Admission Strategy-May-26-2022 final.pptxAdmission Strategy-May-26-2022 final.pptx
Admission Strategy-May-26-2022 final.pptx
 
Naac by unus
Naac by unusNaac by unus
Naac by unus
 
NAAC Assessment && Accreditation - Introduction
NAAC Assessment && Accreditation - IntroductionNAAC Assessment && Accreditation - Introduction
NAAC Assessment && Accreditation - Introduction
 
Career counselling
Career counsellingCareer counselling
Career counselling
 
Best immigration consultants ppt
Best immigration consultants pptBest immigration consultants ppt
Best immigration consultants ppt
 
Cuet exam pattern
Cuet exam patternCuet exam pattern
Cuet exam pattern
 

Viewers also liked

Association for computing machinery (acm)
Association for computing machinery (acm)Association for computing machinery (acm)
Association for computing machinery (acm)Rana Muhammad Asif
 
Basic Problems and Solving Algorithms
Basic Problems and Solving AlgorithmsBasic Problems and Solving Algorithms
Basic Problems and Solving AlgorithmsNopadon Juneam
 
Introduction to ACM Chapter Services
Introduction to ACM Chapter ServicesIntroduction to ACM Chapter Services
Introduction to ACM Chapter ServicesAnirudha Bose
 

Viewers also liked (6)

Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Association for computing machinery (acm)
Association for computing machinery (acm)Association for computing machinery (acm)
Association for computing machinery (acm)
 
Den sosiale turisten
Den sosiale turistenDen sosiale turisten
Den sosiale turisten
 
What is ACM?
What is ACM?What is ACM?
What is ACM?
 
Basic Problems and Solving Algorithms
Basic Problems and Solving AlgorithmsBasic Problems and Solving Algorithms
Basic Problems and Solving Algorithms
 
Introduction to ACM Chapter Services
Introduction to ACM Chapter ServicesIntroduction to ACM Chapter Services
Introduction to ACM Chapter Services
 

Similar to Acm icpc-briefing-prof-nbv

M.tech admission in india
M.tech admission in indiaM.tech admission in india
M.tech admission in indiaEdhole.com
 
M.tech admission in india
M.tech admission in indiaM.tech admission in india
M.tech admission in indiaEdhole.com
 
Distributed Computing & MapReduce
Distributed Computing & MapReduceDistributed Computing & MapReduce
Distributed Computing & MapReducecoolmirza143
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_progTAlha MAlik
 
Meetup 29042015
Meetup 29042015Meetup 29042015
Meetup 29042015lbishal
 
part 1 - intorduction data structure 2021 mte.ppt
part 1 -  intorduction data structure  2021 mte.pptpart 1 -  intorduction data structure  2021 mte.ppt
part 1 - intorduction data structure 2021 mte.pptabdoSelem1
 
Introduction To Autumata Theory
 Introduction To Autumata Theory Introduction To Autumata Theory
Introduction To Autumata TheoryAbdul Rehman
 
lec01.pdf
lec01.pdflec01.pdf
lec01.pdfBeiYu6
 
Fundamentals of computer system and Programming EC-105
Fundamentals of computer system and Programming EC-105Fundamentals of computer system and Programming EC-105
Fundamentals of computer system and Programming EC-105NUST Stuff
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin敬倫 林
 
Multimodal Learning Analytics
Multimodal Learning AnalyticsMultimodal Learning Analytics
Multimodal Learning AnalyticsXavier Ochoa
 

Similar to Acm icpc-briefing-prof-nbv (20)

M.tech admission in india
M.tech admission in indiaM.tech admission in india
M.tech admission in india
 
M.tech admission in india
M.tech admission in indiaM.tech admission in india
M.tech admission in india
 
Unit no_1.pptx
Unit no_1.pptxUnit no_1.pptx
Unit no_1.pptx
 
computer architecture.
computer architecture.computer architecture.
computer architecture.
 
Lecture 1 (bce-7)
Lecture   1 (bce-7)Lecture   1 (bce-7)
Lecture 1 (bce-7)
 
Distributed Computing & MapReduce
Distributed Computing & MapReduceDistributed Computing & MapReduce
Distributed Computing & MapReduce
 
Ch1
Ch1Ch1
Ch1
 
Ch1
Ch1Ch1
Ch1
 
Sub ICT Seminar.pptx
Sub ICT Seminar.pptxSub ICT Seminar.pptx
Sub ICT Seminar.pptx
 
chapter 1
chapter 1chapter 1
chapter 1
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_prog
 
Meetup 29042015
Meetup 29042015Meetup 29042015
Meetup 29042015
 
Computer Programming_Unit 1
Computer Programming_Unit 1Computer Programming_Unit 1
Computer Programming_Unit 1
 
part 1 - intorduction data structure 2021 mte.ppt
part 1 -  intorduction data structure  2021 mte.pptpart 1 -  intorduction data structure  2021 mte.ppt
part 1 - intorduction data structure 2021 mte.ppt
 
Introduction To Autumata Theory
 Introduction To Autumata Theory Introduction To Autumata Theory
Introduction To Autumata Theory
 
lec01.pdf
lec01.pdflec01.pdf
lec01.pdf
 
Digital_system_design_A (1).ppt
Digital_system_design_A (1).pptDigital_system_design_A (1).ppt
Digital_system_design_A (1).ppt
 
Fundamentals of computer system and Programming EC-105
Fundamentals of computer system and Programming EC-105Fundamentals of computer system and Programming EC-105
Fundamentals of computer system and Programming EC-105
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin
 
Multimodal Learning Analytics
Multimodal Learning AnalyticsMultimodal Learning Analytics
Multimodal Learning Analytics
 

More from Nagasuri Bala Venkateswarlu

Swift: A parallel scripting for applications at the petascale and beyond.
Swift: A parallel scripting for applications at the petascale and beyond.Swift: A parallel scripting for applications at the petascale and beyond.
Swift: A parallel scripting for applications at the petascale and beyond.Nagasuri Bala Venkateswarlu
 
Let us explore How To solve Technical Education in India.
Let us explore How To solve Technical Education in India.Let us explore How To solve Technical Education in India.
Let us explore How To solve Technical Education in India.Nagasuri Bala Venkateswarlu
 
Do We need to rejuvenate our self in Statistics to herald the 21st Century re...
Do We need to rejuvenate our self in Statistics to herald the 21st Century re...Do We need to rejuvenate our self in Statistics to herald the 21st Century re...
Do We need to rejuvenate our self in Statistics to herald the 21st Century re...Nagasuri Bala Venkateswarlu
 

More from Nagasuri Bala Venkateswarlu (20)

Building mathematicalcraving
Building mathematicalcravingBuilding mathematicalcraving
Building mathematicalcraving
 
Nbvtalkonmoocs
NbvtalkonmoocsNbvtalkonmoocs
Nbvtalkonmoocs
 
Nbvtalkon what is engineering(Revised)
Nbvtalkon what is engineering(Revised)Nbvtalkon what is engineering(Revised)
Nbvtalkon what is engineering(Revised)
 
Swift: A parallel scripting for applications at the petascale and beyond.
Swift: A parallel scripting for applications at the petascale and beyond.Swift: A parallel scripting for applications at the petascale and beyond.
Swift: A parallel scripting for applications at the petascale and beyond.
 
Nbvtalkon what is engineering
Nbvtalkon what is engineeringNbvtalkon what is engineering
Nbvtalkon what is engineering
 
Fourth paradigm
Fourth paradigmFourth paradigm
Fourth paradigm
 
Let us explore How To solve Technical Education in India.
Let us explore How To solve Technical Education in India.Let us explore How To solve Technical Education in India.
Let us explore How To solve Technical Education in India.
 
Nbvtalkstaffmotivationataitam
NbvtalkstaffmotivationataitamNbvtalkstaffmotivationataitam
Nbvtalkstaffmotivationataitam
 
top 10 Data Mining Algorithms
top 10 Data Mining Algorithmstop 10 Data Mining Algorithms
top 10 Data Mining Algorithms
 
Dip
DipDip
Dip
 
Anits dip
Anits dipAnits dip
Anits dip
 
Bglrsession4
Bglrsession4Bglrsession4
Bglrsession4
 
Gmrit2
Gmrit2Gmrit2
Gmrit2
 
Introduction to socket programming nbv
Introduction to socket programming nbvIntroduction to socket programming nbv
Introduction to socket programming nbv
 
Clusteryanam
ClusteryanamClusteryanam
Clusteryanam
 
Nbvtalkataitamimageprocessingconf
NbvtalkataitamimageprocessingconfNbvtalkataitamimageprocessingconf
Nbvtalkataitamimageprocessingconf
 
Nbvtalkatjntuvizianagaram
NbvtalkatjntuvizianagaramNbvtalkatjntuvizianagaram
Nbvtalkatjntuvizianagaram
 
Webinaron muticoreprocessors
Webinaron muticoreprocessorsWebinaron muticoreprocessors
Webinaron muticoreprocessors
 
Nbvtalkonfeatureselection
NbvtalkonfeatureselectionNbvtalkonfeatureselection
Nbvtalkonfeatureselection
 
Do We need to rejuvenate our self in Statistics to herald the 21st Century re...
Do We need to rejuvenate our self in Statistics to herald the 21st Century re...Do We need to rejuvenate our self in Statistics to herald the 21st Century re...
Do We need to rejuvenate our self in Statistics to herald the 21st Century re...
 

Recently uploaded

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 

Recently uploaded (20)

Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 

Acm icpc-briefing-prof-nbv

  • 1. An awareness program on ACM –ICPC( Programming Competition) A Briefing Session 1 Prof NB Venkateswarlu, B.Tech, M.Tech(IIT-K), PhD(BITS, Pilani), PDF(U of Leeds, UK) AITAM, Tekkali 10th March 2015 9.30AM
  • 2. 2 What is ACM?  Internationally, ACM stands for Association of Computing Machinery
  • 3. About ACM ACM, the Association for Computing Machinery www.acm.org, is the world’s largest educational and scientific computing society, uniting computing educators, researchers and professionals to inspire dialogue, share resources and address the field’s challenges. ACM strengthens the computing profession’s collective voice through strong leadership, promotion of the highest standards, and recognition of technical excellence. ACM supports the professional growth of its members by providing opportunities for life-long learning, career development, and professional networking.
  • 4. International Collegiate Programming Contest (ICPC) World renowned programming competition. Regionals  World Finals
  • 8. 8 Annual Code Match (ACM)  We borrowed the acronym 'ACM' and made it Annual Code Match  The IBM-Annual Code Match 2006 & 2007 – Modelled after ACM-ICPC, but held at university-level, closed doors – Sponsored by IBM Malaysia – http://fit.mmu.edu.my/codematch  The winning teams were sponsored to ACM- ICPC Asia Regionals in Manila (Oct 2006) and Singapore (Dec 2007)!
  • 10. Where are you great India, so called the mighty IT Giant?
  • 11.
  • 12.
  • 13. 13 Why take part in competitions?  Develop your problem-solving skills  To break Google, FB, Yahoo, Amazon Interviews and earn 1.7Cr package and gloom in News Papers and bring fame to your parents, and to your college,  To win some cash $$ or prizes.   An opportunity to represent the university in various competitions if selected  …and normally that's fully sponsored!  It’s where you can demonstrate what you are really capable of  Learn to compete seriously!  Good for your CV?
  • 14. 14 Why this two day course is organized?  Find the cream of the crop...to represent your Institute in future competitions (Especially ACM- ICPC)  Develop a problem-solving 'culture' among our students  Provide the talented students a platform to increase their potentials (forget about the classroom...)  Stone sharpens stone  ALSO TO KNOW YOUR INTEREST TO CONTINUE THIS ACTIVITY.
  • 15. How I am qualified for the delivery of this two day course?
  • 17.
  • 21. 21 ACM Rules  Languages: C, C++, Java  Each team will be provided with 1 computer usually with Linux  Allowed to bring in 25 pages of notes  Contest will be run for 5 hours – Food and drinks will be normally provided  Number of questions: 7-10  Contest is conducted using PC2 system – Submission of answers – Clarification – Judging (human and/or computer judge) – Live scoreboard
  • 22. 22 Scoring System  Solutions to problems submitted are called runs.  Teams are ranked according to most problems solved  Teams that solve the same number of problems are ranked by – Least total time – Earliest time of submittal of last accepted run
  • 23. 23 Scoring System  Total time = Sum of time consumed for each problem  Time consumed = Time elapsed from beginning of contest to submittal of accepted run  Each rejected run: +20 penalty minutes  No time is consumed for an unsolved problem  Output must be exactly same as required format, otherwise considered wrong!
  • 24. 24 Sample Scoreboard 2006 ACM Final Scoreboard
  • 25. Submitting • You will receive one of several responses: – Format error – Time limit reached – Runtime error (division by 0, out of memory, exception thrown, etc.) – Compile error – Wrong answer – Correct! • The judges only give you one at a time – If you have two or more problems, you’ll usually only get the more embarrassing of them
  • 26. Always have someone typing • Typing and compiling is time intensive, and there’s only one keyboard – If your program isn’t working, print it and debug it by hand – Let someone else sit and type! • If you’re waiting for the computer, write some code out by hand or ask a neighbor for their opinion on your algorithm • If it has you read until end of input, use: while (cin >> x)
  • 27. Questions  You can submit questions to the judges about problems  Updates will be given to everyone if there is a typo or other error  You will get one of two responses: – A clarification – No answer (i.e. read the problem more closely)
  • 28. Test the judge’s input  They give you 1 or 2 sample inputs and solutions; test them! – There will normally be simple cases.  Make sure your format exactly matches the judge’s sample output! – They use a file compare (via a script) so it must be very close
  • 29. End cases  The judges are very tricky with their tests  If the problem says inputs will be between A and B, you can almost bet that inputs of size A and B will be tested  Be wary of carefully worded questions!
  • 30. 30 Typical ACM Problem Format (1) Problem description (2) Input description (3) Output description (4) Sample input (5) Sample output
  • 31. 31 Standard I/O technique  Input stream has to be continuously inputted with data (number, char, string, etc.) until it finishes.  Output will show all that has been processed.  May not be the best way to test your codes, but it is required for submission.  Use Input File Piping technique for easier testing & debugging of data
  • 32. 32 Sample Problem  Finding the absolute difference between 2 numbers  Demo – Standard “continuous” I/O (for submission of solution) – Input File Piping (for testing/debugging) Sample Input: 3 7 2 -2 Sample Output: 4 4
  • 33. 33 File Reading – Not often  Possibly need to do file reading if the problems require you to specifically use a certain name of input text file such as “data.txt”, but this is rare.
  • 34. 34 (PC)2 Submission System  Software for teams to submit their answers for evaluation. Result feedback (Accepted or Rejected with specific reason) is quite fast.  Software allows teams to test (compile and run) their answers with the server environment.  Answers are evaluated with judges' own set of test data
  • 35. Some Important Concepts  Backtracking  Complete Search  Dynamic Programming  Encryption  Game/Puzzle  Chess  Sudoku  Graph Theory  Greedy  Mathematical
  • 36. Some Important Concepts  Bases  General  Geometry  Perfect Squares  Physics  Parsing  Straightforward  Tree
  • 37. Be generous with your memory!  Make your arrays twice as big as necessary – Off by one error are difficult to find!  Use the STL (strings, vectors, everything!)  Use long long instead of int  Use double instead of float
  • 38. Code quickly at the cost of efficiency  The faster you type, the faster you submit!  Use the STL if it makes it easier for you – If you can’t remember how to use the STL sort, write a simple (bubble?)sort. Who cares!  Generally, if you get a “time limit reached”, your algorithm needs to be changed, not just little things in your code
  • 39. Helpful suggestion  Bring printed code, such as the algorithms we’ll talk about. • You won’t have to remember them and know you have a working/correct version too. – If someone is not typing in an answer, type in the algorithm so the template is ready to use. – Also data structures you may want to use (trees for example). – Including a “read a file” code. You know it works, then one least thing to think about.
  • 40. math  Number theory – Very popular in the program contests – For ICPC, you need a rather small but useful set • Prime table generation, primality testing, greatest common divisor, modular arithmetic and congruence (solving linear congruences), and Euler’s – A Note, Java’s BigInteger class has a number of number-theoretic functions, like gcd, modular exponentiation, primality testing, etc.
  • 41. String manipulation  There have been a number of string manipulation questions over the years.  Learn the string library – At the least substring, replace, find etc. – Regex maybe really helpful.
  • 42. algorithms  Brute force algorithms – From nested loop algorithms to backtracking (easier with recursion). • Breath first search. • Depth first search is recursive and has nice bracktracking features.  Dynamic Programming – Recursive algorithm that is composed of subproblems • Coin flipping and fibonacci are simple examples • Longest Common Subsequence (LCS), Longest Increasing Subsequence (LIS), Optimal Binary Search tree (OBST), 0-1 knapsack, edit distance, Matrix Chain Product are increasing harder examples.
  • 43. algorithms  Trees and priority queues, not necessary an algorithms, but can speed things up.  Graph theory – How to represent things and then use BFS and DFS, and topological sorting. • Does the graph have cycles?
  • 44. Classic Problems algorithms  Shortest paths (Dijkstra for example)  Spanning trees (Prim or Kruskal)  Eulerain paths and circuits  Matchings in bipartite graphs  Network flow (max flow, min cost flows)  Geometry.
  • 45. STL: Deque  #include <deque>  deque<int> x;  x.push_back(20); x.pop_back(); x.back(); x.push_front(20); x.pop_front(); x.front();  x.resize(100);  x[10] OR x.at(10);  x.clear();
  • 46. STL: Strings • #include <string> • string str; string str(“foo”); string str(10, ‘c’); • str += “bar”; • Find – str.find(“aaba”); str.rfind(“aaba”); – str.find_first_of(“AEIOU”); – str.find_last_not_of(“AEIOU”, 5); – Returns an int, or string::npos if none found • str.substr(int position, int length)
  • 47. STL: Algorithms • #include <algorithm> • swap(a, b); // Any type that has = can go here! • reverse(arr, arr + 10); reverse(deq.begin(), deq.end()); • Sorting – sort(arr, arr + 10); sort(deq.begin(), deq.end()); – sort(arr, arr + 10, lessThanFunction); bool lessThanFunction(const Type& t1, const Type& t2) { if (t1 < t2) return true; return false; }
  • 48. STL: Algorithms  #include <algorithm>  Permutations int x[] = {3, 5, 4, 1, 2}; sort(x, x + 5); do { // stuff } while (next_permutation(x, x + 5));
  • 49. STL: formatting • #include <iomanip> • double d = 12345.6789; • cout << d << endl; • cout << setprecision(3) << d << endl; • cout << setprecision(3) << fixed << d << endl; • cout << setprecision(1) << fixed << 0.55 << endl; • int i = 42; • cout << hex << i << endl; • cout << hex << uppercase << i << endl; • cout << i << endl; • cout << dec << i << endl; • 12345.7 • 1.23e+04 • 12345.679 • 0.6 • 2a • 2A • 2A • 42
  • 50. Algorithms  Brush up on – depth-first search, breadth-first search (or just use iterative deepening DFS) • N-Trees, but lots of other uses as well.  minimum spanning trees http://en.wikipedia.org/wiki/Minimum_span ning_tree – Lots of varying algorithms listed at the bottom of the page
  • 51. Algorithms (2)  shortest path, like Dijkstra’s algorithm – http://en.wikipedia.org/wiki/Dijkstra’s_algorit hm – http://en.wikipedia.org/wiki/Shortest_path_pr oblem  (Max) flow problems – http://www-b2.is.tokushima- u.ac.jp/~ikeda/suuri/maxflow/Maxflow.shtml • Good demo of max flow and min cut algorithms. • Also links to some other versions of spanning tree algorithms.
  • 52. Algorithms (3)  Greatest common divisor is a fun one to remember too – And remember, if gcd(a, b) == 1, then a and b are relatively prime!
  • 53. Dynamic programming/memoization • Recursive algorithm that is composed of subproblems – You keep recomputing the subproblems! – Save them in an array and look them up – Start with the recursive version first, then modify it to save work • Examples – Fibonacci – Coin problem
  • 55. Geometric algorithms  Intersection – Four points: a1, a2, b1, b2 – Compute: • dir1 = direction(b1, b2, a1) • dir2 = direction(b1, b2, a2) • dir3 = direction(a1, a2, b1) • dir4 = direction(a1, a2, b2) – If dir1/dir2 are opposite signs, and dir3/dir4 are opposite signs, they intersect
  • 57. 57 Debunking some myths  I know C, C++, C#, Java, Pascal, Perl, Python, LISP,… I don’t think I have much problem with programming!  Good in programming == Good in problem solving  Look, I know how to solve this problem on paper! In ACM, programming is just a tool Can you code it? != Here, we want to solve problems, not write nice programs  I can write a really nice program, with neat functions and classes you know!
  • 58. Some Important Difficulties of students. Most students do not perform well under limited time pressure. This hinders their performance not only in programming competitions, but also in employment interviews that focus on immediate problem solving.  Students have difficulty with the analysis of new problems and being able to select an appropriate algorithm.  Students often have difficulty expressing their point of view on how a problem should be solved. They might lack confidence or communication skills, or they may not have experience in explaining the workings of an algorithm.  Students at the Junior year level have had little or no exposure to teamwork in a problem solving context.
  • 59. Some useful online judging sites  www.spoj.com  www.wcipeg.com  http://acm.pku.edu.cn/JudgeOnline/  icpcres.ecs.baylor.edu/onlinejudge  www.iarcs.org.in  https://www.hackerrank.com  https://www.hackerrank.com
  • 60. 60 Useful Resources  “Programming Challenges: The Programming Contest Training Manual” by Steven Skiena & Miguel Revilla – http://fit.mmu.edu.my/codematch/acm_downloads.php  UVA Problemset Archive – favourite spot for people to train for ACM contests – http://uva.onlinejudge.org/ – PLEASE register an account and try out the problems!   ACM-ICPC Live Archive – past year regional/world final questions – http://acmicpc-live-archive.uva.es/nuevoportal/
  • 61. Dictionary of Algorithms and Data Structures maintained by NIST  http://www.nist.gov/dads
  • 62. Skiena Steven, Stony Brook Algorithm Repository,  http://www.cs.sunysb.edu/~algorith
  • 63. 63 The “Guidebook”  Data Structures  Strings  Sorting  Arithmetic  Combinatorics  Number Theory  Backtracking  Graph Traversal  Graph Algorithms  Dynamic Programming  Grids  Geometry  Computational Geometry
  • 64. 64 Some things to kickstart…  Register in mmu-acm Google Group – for communication, discussion, sharing – http://groups.google.com/group/mmu-acm – Invitation will be sent out soon…  You may work closely with people whom you’re comfortable with. Teamwork can be forged early.  Continue to sharpen your programming skills  Learn useful algorithms for problem-solving
  • 66. 66 Session 2 OK, we are going to try some very simple problems! 
  • 67. Counting characters in a range • Input will consist of two integers, 0 < N < 100 • For each of the numbers in between these two numbers (inclusive), count the occurrences of each digit • Example: 17 21 – 17 18 19 20 21 – 0=>1 7=>1 1=>4 8=>1 2=>2 9=>1
  • 68. Counting characters in a range • cin >> a >> b; for (i = a; i <= b; ++i) { ++arr[i / 10]; ++arr[i % 10]; } • 17 21 ? • 21 17 ?
  • 69. Problem #1  If you have a one-dimensional array of unsorted number such as 0, 9, 3, 15, 4, 11, 25, 3, 0  Convert it into a two-dimensional array whose numbers of row and column are equal, such that the largest element is at the top left corner, and continue to put the next largest element in-ward in a clock- wise manner 25 15 11 0 0 9 3 3 4
  • 70. Solution to HW Problem #1 1. Let input_size = the size of input array 2. table_size = ceil(sqrt(input_size)) – Note that ceil() is the function that rounds the input number to the nearest integer greater than the input number – sqrt() is the square root function. 1. Sort input array (from smallest value to largest value)
  • 71. i. Create an empty array of input_size and name it temp ii. Set value index = 0 iii. Find the smallest value in input array and put it in temp[index] iv. Replace the smallest value with ∞ v. index = index + 1 vi. Repeat from iii to vi until index == input_size 4. Create 2-dimensional array of table_size*table_size named output_array Solution to HW Problem #1 (ii)
  • 72. 5. Set index_row = index_column = 0, index = input_size-1 6. do 7. output_array[index_row][index_column] = temp[index] 8. [index_row, index_column] = next(index, input_size, table_size) 9. index = index – 1; 10. While index >= 0 11. Return output_array Solution to HW Problem #1 (iii)
  • 73. Subroutine next(index, index_row, index_col, input_size, table_size) 1. track_dex = input_size – index -1 2. If track_dex < 4(table_size-1) if track_dex < table_size return [index_row, index_col +1] else if track_dex < 2*table_size – 1 return [index_row+1, index_col] else if track_dex < 3*table_size – 2 return [index_row, index_col-1] else return [index_row – 1, index_col] 1. Else return next(index-4(table_size-1),index_row, index_col, input_size – 4(table_size- 1),table_size – 2);
  • 74. Session 3  Programming Examples Continued
  • 75. Session 4 – Recapitulation of Mathematics
  • 76. Session – 5 Recapitulation of Data Structures
  • 81. Thanks  To you  The Management  The Principal  Head, Dr Srinivasarao Garu  Mr. Mahesh