Skip to main content

Posts

Showing posts from April, 2019

Prepare for Competitive Programming

I started learning C++ from scratch during my first year of College. I knew nothing about programming, algorithms or data structures.N ow i am more comfortable with data structure and algorithms. What language should you choose? C++ — Highly recommended! It’s very fast. Implementing different algorithms takes little time because of STL. C++ is accepted in all competitions.  I’ve been using it since my first line of code. C — Go and learn C++ because of STL. If you have knowledge of C, you are ready to code in C++ as well. JAVA — It’s slow. But it has Big Integer class, even if there are very few problems that require using it. If the time limit is tight, you will get Time limit exceeded. Java is not accepted in all competitions. Where can you practice? I recommend  Sphere Online Judge (SPOJ) . It’s effective in terms of quality and quantity. Editorials and solutions are available online if you get stuck while solving problems. Supporting websites  SPOJ Toolkit  and  Prob

C++ Standard Template Library Hacks I like

C++’s STL is a boon. Not only is C++ extremely fast, in terms of execution, for programming contests – but the addition of STL makes it an extremely strong contender for my “favorite programming contest language”. 1. __gcd(a, b) The method to find the gcd of two numbers is  __gcd(a, b) . (Note: There are TWO underscores, not ONE before the function name) This method is defined under  #include<bits/stdc++.h>  and returns the greatest common divisor of integers or longs  a  and  b . This is my go-to in majority of number theory problems involving GCDs or LCMs. 2. __builtin_popcount(a) This method returns the number of ones present in the binary notation of the number. i.e.  __builtin_popcount(7)  = 3,  __builtin_popcount(5)  = 2,  __builtin_popcount(4)  = 1 3. __builtin_ctz(a) This method returns the number of trailing zeros of a number  a . Consequently, I’ve also found this convenient in cases where I’m trying to find the least significant bit of a num