In the era of competitive programming optimization is a must.Most of the optimization in a code is done inside an algorithm,rather then implementation. Bit manipulation is one of the simplest and most useful and effective low level optimization. In this post I am going to discuss about bit manipulation in C++.Further I will discuss about a C++ STL “bitset”. Whatever we do in our computer it only understands 0 or 1.All data saved in our computer is in binary. Bit-wise operation works with each bit individually.The very basic of Bit-wise manipulation is the Bit-wise operators.Which are And(&), OR(|), NOT(!), XOR(^). In case of bit operation every bit of a data follows the rule above. For example: 110 & 101 is equal to 100 (consider each bit individually). 110 | 101 is equal to 111 (consider each bit individually). and so on. With this basic concept we will move on to next where [...]
In this post I am gonna discuss about UVA problem number 10025.This is a mathematics ad-hoc problem.I will not provide you the code.The Problem specification and the way to solve it is discussed below. The ? 1 ? 2 ? … ? n = k problem The problem Given the following formula, one can set operators ‘+’ or ‘-’ instead of each ‘?’, in order to obtain a given k ? 1 ? 2 ? … ? n = k For example: to obtain k = 12 , the expression to be used will be: – 1 + 2 + 3 + 4 + 5 + 6 – 7 = 12 with n = 7 The Input The first line is the number of test cases, followed by a blank line. Each test case of the input contains integer k (0<=|k|<=1000000000). Each test case will be separated by a single line. The Output For each test [...]
In this series of tutorial I will introduce you to the most easy and powerful language of today, Python. It is said that Python is one of those rare languages which can be said to be both simple and powerful.Python is such a language which is perfect for the beginners to learn programming and the experts to build apps games websites and so on.No more talk.Lets dive to this friendly snake Installation: Simply visit http://www.python.org/ and download python 3.3.2. After that run the .exe file and do simple installation process. After completing your installation you will find a program named IDLE(Python GUI). If you don’t find it, just go to your start menu and search for it. When you find it you are ready to go. OK,now we are ready to start our journey to the most simple,powerful and cutest snake of the world.Python.All the basic program starts with a hello world execution.So your task is [...]
Hello every one.Today I am gonna discuss about a well-known puzzle,”Magic Square”.It is a very simple puzzle,so no more talk.Let’s see Magic Square. Background: Magic square is arrangement of numbers in a grid,simply a two dimension matrix,where the sum of each row,column,diagonal is same.The row and column of the matrix is equal (nXn matrix).