Posts

Showing posts from December, 2020

MARBLES codechef explaination...

Image
  In our problem we are having N marbles we have to pick K colors. And it is necessary that at least one marble of each color.  So now we left with N-K marbles which can be of K colors. Now this problem turns into a problem of counting in how many  ways we can distribute N-K marbles into K distinguishable colors, with no constraints. This is a problem of "combinations with repetitions" , also known as the "stars and bars problem" .  Lets journalize this whole situation for a while … We can also have an r- combination of n items with repetition. And these two conditions must be fulfilled:- order doesn't matter. we can select the same thing multiple times i.e; repetition is allowed. For example: We can choose 6 marbles where only 3 colors are available. Colors are Blue(B), Red(R) , Yellow(Y).                How many different selections can we make? Since order doesn’t matter we ‘ll list all of our selection...

Mystery of Plain, Signed and Unsigned

Image
  T here are two big players to whom this discussion begins with INT and CHAR.  Now, firstly specification about the compiler I am using from which all the following results are produced:     g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0 Let's get started, First we will demystify integers. Integer is an integral type that can represent positive and negative   whole numbers including 0  such as -1, -2, -3 … 0 … 10, 4996, 97634 etc. Since we are having infinite   negative and positive numbers in mathematics but we are having finite amounts of memory in our  computer systems. So we have to adopt some method to store different sizes of integers in our program. For example, in few use cases we might require small sets of integers numbers or in    another we might require large integer values.  C++ has created 4 different fundamental integer types available for use are as follows:- short  int l...