Introductory Lecture Topics: Basics, Resources, STL, Bitwise Tricks, GDB
Introductory Lecture Topics: Basics, Resources, STL, Bitwise Tricks, GDB
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
Discussion camp not a lecture series. You need to show motivation. To help you code better and faster, introduce you to new tricks mostly to help you do well in programming contests.
League of Programmers
Introductory Lecture
Language Issues
League of Programmers
Introductory Lecture
Language Issues
Language We stress on: C++ Slower languages like java and python time out on many judges.
League of Programmers
Introductory Lecture
Language Issues
Language We stress on: C++ Slower languages like java and python time out on many judges. C has too restrictive and does not support stl/ templates / classes.
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
Compete against Indian coders in live contests Codechef As problem archive Codeforces/Spoj/UVA/Topcoder/Project Euler
League of Programmers
Introductory Lecture
Compete against Indian coders in live contests Codechef As problem archive Codeforces/Spoj/UVA/Topcoder/Project Euler Short Programming Contests Codeforces/Topcoder
League of Programmers
Introductory Lecture
Compete against Indian coders in live contests Codechef As problem archive Codeforces/Spoj/UVA/Topcoder/Project Euler Short Programming Contests Codeforces/Topcoder Tougher Problems acm.sgu.ru/Codechef Monthly challenge/IOI/ACM ICPC previous years archive/Topcoder level 3
League of Programmers
Introductory Lecture
India: ACM ICPC/ IOPC/ Shastra OPC/ Codecraft/ Codechef Monthly Challenge/ Codechef Cook o
League of Programmers
Introductory Lecture
India: ACM ICPC/ IOPC/ Shastra OPC/ Codecraft/ Codechef Monthly Challenge/ Codechef Cook o World: Topcode SRMs/ Codeforces/ Facebook Hacker Cup/ Google Code Jam
League of Programmers
Introductory Lecture
Common Problems
Overow
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays Solution: either use vector stl(convenient) or global arrays of large enough size(faster)
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays Solution: either use vector stl(convenient) or global arrays of large enough size(faster) Comparing Doubles
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays Solution: either use vector stl(convenient) or global arrays of large enough size(faster) Comparing Doubles Solution: Always keep cushion of a small .
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays Solution: either use vector stl(convenient) or global arrays of large enough size(faster) Comparing Doubles Solution: Always keep cushion of a small . Segmentation faults
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays Solution: either use vector stl(convenient) or global arrays of large enough size(faster) Comparing Doubles Solution: Always keep cushion of a small . Segmentation faults Solution: Use gdb gdb tutorial
League of Programmers
Introductory Lecture
Common Problems
Overow Use data type of appropriate size. Choose data type of every variable carefully based on the constraints of the problem Passing Multi Dimensional Arrays Solution: either use vector stl(convenient) or global arrays of large enough size(faster) Comparing Doubles Solution: Always keep cushion of a small . Segmentation faults Solution: Use gdb gdb tutorial From Your side
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ?
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA Map: Advanced set Problem:spoj.pl/problems/SUBSEQ
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA Map: Advanced set Problem:spoj.pl/problems/SUBSEQ string class and stringstream to parse strings useful mostly for topcoder SRM problems
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA Map: Advanced set Problem:spoj.pl/problems/SUBSEQ string class and stringstream to parse strings useful mostly for topcoder SRM problems memset/ll: initialize arrays
League of Programmers
Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA Map: Advanced set Problem:spoj.pl/problems/SUBSEQ string class and stringstream to parse strings useful mostly for topcoder SRM problems memset/ll: initialize arrays Queue can be use as queue and stack
League of Programmers Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA Map: Advanced set Problem:spoj.pl/problems/SUBSEQ string class and stringstream to parse strings useful mostly for topcoder SRM problems memset/ll: initialize arrays Queue can be use as queue and stack bitset(next section)
League of Programmers Introductory Lecture
STL
Website: http://www.cplusplus.com/reference what is template ? Vector: Dynamic size arrays with insertion/deletion to/from arbitrary locations Set: Just like a mathematical set. Problem:spoj.pl/problems/WEIRDFN Problem:http://www.spoj.pl/problems/HOMO/ Problem:spoj.pl/problems/HISTOGRA Map: Advanced set Problem:spoj.pl/problems/SUBSEQ string class and stringstream to parse strings useful mostly for topcoder SRM problems memset/ll: initialize arrays Queue can be use as queue and stack bitset(next section) League of Programmers dene your own MACROS: for Introductory Lecture blitz-coding
League of Programmers
Introductory Lecture
League of Programmers
Introductory Lecture
Numbers are stored in binary and processing on bits is way faster Our weapons: << (left shift), >> (right shift), &(bitwise and), |(bitwise or ), (bitwise xor ) (bitwise not)
League of Programmers
Introductory Lecture
Numbers are stored in binary and processing on bits is way faster Our weapons: << (left shift), >> (right shift), &(bitwise and), |(bitwise or ), (bitwise xor ) (bitwise not) speed up the code by upto 100 times.
League of Programmers
Introductory Lecture
Numbers are stored in binary and processing on bits is way faster Our weapons: << (left shift), >> (right shift), &(bitwise and), |(bitwise or ), (bitwise xor ) (bitwise not) speed up the code by upto 100 times. caution: try to use bitwise operations on unsigned integers only
League of Programmers
Introductory Lecture
Beauty of Bitwise
League of Programmers
Introductory Lecture
Beauty of Bitwise
Example: Any subset of {0,1. . . 31} is a single int Do set union/intersection/complement in one operation increment /decrement all elements by x in one operation
League of Programmers
Introductory Lecture
Beauty of Bitwise
Example: Any subset of {0,1. . . 31} is a single int Do set union/intersection/complement in one operation increment /decrement all elements by x in one operation Even more: Find if x S. Generate all subsets of S in 2|S| time Generate all subsets of {1..n} changing one bit at a time Generate all subsets of S which have exactly t elements Count the number of elements of elements in a set S Remove smallest element from S check if |S| = 1
League of Programmers
Introductory Lecture
Beauty of Bitwise
Example: Any subset of {0,1. . . 31} is a single int Do set union/intersection/complement in one operation increment /decrement all elements by x in one operation Even more: Find if x S. Generate all subsets of S in 2|S| time Generate all subsets of {1..n} changing one bit at a time Generate all subsets of S which have exactly t elements Count the number of elements of elements in a set S Remove smallest element from S check if |S| = 1 Never multiply or divide or take remainder modulo power of 2
League of Programmers Introductory Lecture
Practice Probems
More tricks: graphics.stanford.edu/seander/bithacks.html lab.polygonal.de/2007/05/10/bitwise-gems-fast-integer-math bits.stephan-brumme.com Problems: codechef.com/problems/TEAMSEL spoj.pl/problems/PIZZALOC acm.sgu.ru/problem.php?contest=0&problem=249 codechef.com/problems/SEQUENCE spoj.pl/problems/NGM2 spoj.pl/problems/VILLAGES bitwise dp: community.topcoder.com/stat?c=problem statement&pm=6725&rd=101 community.topcoder.com/stat?c=problem statement&pm=6095&rd=991 community.topcoder.com/stat?c=problem statement&pm=6400&rd=100
League of Programmers Introductory Lecture