Skip to main content

Posts

CSES PROBLEMSET

INTRODUCTORY PROBLEMS 1 . WEIRD ALGORITHM SOLUTION: #include < bits / stdc ++. h > using namespace std ; int main (){ long long n ; //beacuse n can be greater than max size of int. cin >> n ; while ( n != 1 ){ // loop will break when n become 1. cout << n << " " ; if ( n & 1 ) n = n * 3 + 1 ; // when n is odd. else n = n / 2 ; // when n is even. } cout << "1" ; } 2 . MISSING NUMBER SOLUTION : LOGIC: just sum all the inputs and subtract from total sum(n*(n+1)/2). #include < bits / stdc ++. h > using namespace std ; int main (){         long long n , s , sum = 0 ;                cin >> n ;           for ( long long i = 0 ; i < n - 1 ; i ++){              cin >> s ; sum += s ; //sum all the inputs.           }           cout <<(( n *( n + 1 ))/ 2 )- sum ; // and subtracting from total sum. }
Recent posts

The Delicious Cake

JUNE LONG CHALLENGE                                             Problem code : Contain /* Algorithm :-   --> We will create concentric hulls as many as possible.        This can be done using a tracking array to keep track of points which are still unused and passing.        it again in convex hull function We will do this until our track array becomes empty . Algorithm used :-        Finding convex hull using graham scan in O(nlogn) ( For AC )        Finding convex hull using jarvis march in O(n^2) ( For 35 points )  --> Then we will memoize all these convex hulls.        Now we cant create hulls for each query as it will result in  O(q*n^2) complexity (15 points).        So what we will do is create a 2d vector of vectors (in simple words sort of adjacency list)        Then we will process each query. We will check that our point x,y lies in how many convex polygons(layers) in O(q* no of layers).        To check weather a point belongs  to a polygon on not

Tom and jerry solution

JUNE LONG CHALLENGE:                   Problem code: EOEO The Tom and Jerry Game!  logic : For odd case: you just have to find all the values which are even. For even case : Jerry only wins when Jerry strength is even and tom strength is odd so we have to find only those values of JS which can divided by 2 more times than times who in simpler terms (or in bit terms ) we have to to find all that values which have mores zeroes in the end than TS CODE:  #include<bits/stdc++.h> using namespace std; int main(){     long long t;     cin>>t;     while(t--){         long long tom,jerry,count=0;         cin>>tom;         if(tom%2!=0)cout<<(tom-1)/2<<"\n"; /* if tom strength is odd  */         else{                               /* if to strength is even */             jerry = __builtin_ctz (tom);  /* this gcc function returns no. of zeroes at the end of the number in binary representation */             jerry++;                    /* for fi

INTRO

Who am I?.   I am Manish Gupta,a Computer Science Engineering undergrad pursuing my B.Tech in NIT Srinagar and a competitive programmer.I am well versed in C++,Python,JavaScript,C and Bash and as programmer I am eager to learn new things.I'll make sure to post each and every line of elegant code that I write and also ensure to share solutions of some beautiful problems that I encounter.I'll also share some of the projects that I happen to work on. I am also interested in Ethical hacking and am looking forward to pursue a side career in it so I might share some of the "shady" code here :)