Posts

BIT Manipulation

Image
BITMASK -  Two varieties of approach Type -1 --> analyze for each bit (for simplicity -> take array as {1 0 0 1 0} types) Practice ke liye =>  OA wala question  +  Atcoder Type-2  (See both accepted solutions) BITSET   in   cpp NOTE - use bitset => binary representation (NOT decimal) Why do we need? Let's say make boolean array of size 1e9 => High time complexity But with bitset, it will automatically break 1e9 into multiple part of each 32 size (bcz 32-bit system) => time = 1e9/32 Can use in case of take/ not take situation bitset<1000> num --> by default, num = 0 bitset<1000> num (x) --> set num = x => x can be number or binary string num.to_string() => converts to string num.to_ullong() => converts to unsigned long long; can access ith bit as num[i] Operations set sets all bits to  1            --> num.set() reset sets all bits to  0 flip toggles ...

Input Intricacies

Must see for specific input taking Scanf Details # include <stdio.h> int main () {     int m , n ;     scanf ( "(%d)-%d" , & m , & n );     printf ( "%d %d \n " , m , n );     // scanf accept input only if it is in same format as specified     // eg.- here if u write (8) 6 => 8 is in format           =>m=8 but n=0 (by default) bcz not used '-'     scanf ( " (%d) - %d" , & m , & n );     printf ( "%d %d \n " , m , n );     // spaces doesn't matter at start or in between     scanf ( "(%d)-%d " , & m , & n );     printf ( "%d %d \n " , m , n ); // never give space at end bcz compiler ko lgta hai ek aur value hai aage and when u give 1 extra inputs then only it stops . => only first input get stored. *******************************************************************     int a ;     char c ; ...