Solve These Questions for Good BIT Manipulation Intuition | CP Course | EP 65

  Рет қаралды 21,550

Luv

Luv

Күн бұрын

Пікірлер: 72
@almamunsiddiki7697
@almamunsiddiki7697 4 ай бұрын
For the second question: 1. find the number (lim) greater than C with all bits set. 2. a) iterate through lim to 1, Let each number as A; b) in each iteration find B . wich is equal to A^C. c) find maximum product. Code for clear understanding: #include using namespace std; int main(){ int c, a, b; long long ans = 1; cin >> c; int bits = 0, n; n = c; while(n > 0){ bits++; n >>= 1; } int lim = pow(2, bits) - 1; for(int i = lim; i > 0; --i){ b = c ^ i; ans = max(ans , b * 1LL * i); } cout
@devacc9958
@devacc9958 9 ай бұрын
In the second question it can be observed that in all the combinations of A and B to maximise the product (filling 1's for 0 in C), the sum of A and B is constant for given C. Using calculus it can be shown that if sum of two numbers is constant then the product will become larger as the numbers A and B will be close to each other and the product will be maximum when A = B = C / 2. So bits in A and B should be filled in such a way that the difference between A and B is minimum. This can be done by setting all the bits in A in which corresponding bit of C is set except MSB (last bit) and only setting that MSB of B in that case.
@SaurabhChaudhary600
@SaurabhChaudhary600 9 ай бұрын
I had same intution but didn't have the proof, thanks!!
@gourishanker9975
@gourishanker9975 3 жыл бұрын
Luv bhai awesome video.. I have an another approach for 2nd question. Please check if it is correct Instead of generating all the subsets , what we can do is find A and B such that they are as close as possible to each other because we want to maximize the product.. As said above , we we want to choose A and B as close as possible So , lets take A as bigger number and B be the smaller number . Let say ith is position of MSB in C , So we set the ith bit in A And for rest of the set bits in C , we set the bits in B And if the bit is unset in C , we set the bit in both A and B Lets take an example of 13 :: Binary of 13 :- 1101 A :. 1010 B : 0111
@harshal0073
@harshal0073 Жыл бұрын
yes, bro even i thought of the same approach, it is absolutely correct and less with less time complexity
@showrovmiah1035
@showrovmiah1035 8 ай бұрын
I also thought that
@arkojitsanyal3219
@arkojitsanyal3219 3 жыл бұрын
2nd question >> if A^B=C ==> A=C^B..... you just need to brute force for all values of B that are in range 1 to (1
@darshanpagar1894
@darshanpagar1894 2 жыл бұрын
iterations will be same
@pushpajitbiswas3752
@pushpajitbiswas3752 3 жыл бұрын
We can also solve the 2nd problem in O(1) time complexity let say we have our C = 13 all we have to find the power of 2 which is just less than C, in this case it is 8 so A = 8-1 = 7 (always) Now we need B which is also very simple, just do B = A ^ C. Now you have your A and B which is the largest possible pair, now just multiply them :)
@abhaypratap9898
@abhaypratap9898 2 жыл бұрын
Cool 🙃
@souravkumar5120
@souravkumar5120 2 жыл бұрын
but how you reached to this approach ,just hit and trial or some logic.
@pushpajitbiswas3752
@pushpajitbiswas3752 2 жыл бұрын
@@souravkumar5120 By doing dry run and observation brother
@harsh6318
@harsh6318 2 жыл бұрын
Yes i did the same
@vampzzz
@vampzzz 2 жыл бұрын
@@pushpajitbiswas3752 It's a little late to reply but how did you come up with this that A =( pow of 2 just less than C) - 1 would always give us the highest multiple Could you elaborate a bit?
@divyampatni3571
@divyampatni3571 11 ай бұрын
in second question we can further optimize the code. We can just iterate the set_bits.size() loop(the inner loop) from j=0 to j= (set_bits.size()/2 )+1 as after half of the loop has ended the values starting reversing in A and B. I kept an extra iteration for the odd case.
@AsifHussain-gl4ci
@AsifHussain-gl4ci 10 ай бұрын
I am very thankfull of you for teaching in such a simple way. This us the best channel for those who want to do cp. Luv bhaiya will make the hard concepts simple. Thanks ones again.
@algotalk5368
@algotalk5368 3 жыл бұрын
Luv good work u need millions subscribers
@sicklips
@sicklips Жыл бұрын
Easy brute force for second problem : void solve() { int c; cin >> c; long long prod = 0; for(int i = 1; i
@saurabhkumarsingh9550
@saurabhkumarsingh9550 3 жыл бұрын
👌🏻👌🏻👌🏻 great videos h only videos ko frequency km h apke kam ki vajah se.... Is chij ka regret rhta h
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
Bahut hi mast explanation
@dhruvmalik8052
@dhruvmalik8052 11 ай бұрын
Very helpful content
@sahilharad9222
@sahilharad9222 3 жыл бұрын
Fun fact : He wears same T-shirt in all videos 😛
@iamluv
@iamluv 3 жыл бұрын
why waste time in deciding to what to wear xD
@sahilharad9222
@sahilharad9222 3 жыл бұрын
@@iamluv Good job brother 👍
@amad1eus271
@amad1eus271 3 жыл бұрын
But don't you think that's pretty cool XD
@vinflyer2889
@vinflyer2889 3 жыл бұрын
Like Mark Zuckerberg 😏
@sachinupreti7159
@sachinupreti7159 3 жыл бұрын
@@iamluv Itna bhi time waste nahi hota bhai isme at most 1-2 min .
@harry-ns3wh
@harry-ns3wh 2 жыл бұрын
App plz nesting of containers or examples ke sath karao or complex containers STL ke ander apne bhot basic nesting krayi thi like multiset inside there is a set and in set something is there then after comma same as that like multiset university this one isme input kese hongee element or agr ho bhi gye to output kese kre
@harshitsingh4764
@harshitsingh4764 3 жыл бұрын
Ayo😲, Luv express is going at full speed. We are getting new videos (with great content) every 3-4 days.👌🏻
@amad1eus271
@amad1eus271 3 жыл бұрын
I am following these lectures in compititive programming in my jee holidays ( it's so amazing ). I am just searching for some basic path for compititive programming and through this series (a noob like me who doesn't know anything and can't follow anything) I really benefited a lot. I am not preparing for jee adv as I already going to get CSE branch in my desired college XD
@ratneshpal6026
@ratneshpal6026 3 жыл бұрын
East or West Luv is best.
@divanshujain9449
@divanshujain9449 2 жыл бұрын
Sir in the second ques, we just have to set the first bit of A . Then if xor is 1 we ALWAYS set the bit of B and will set bits of both A and B if xor of that bit is 0 .This will always give the correct output in the best optimised way.
@chiraggoyal9646
@chiraggoyal9646 2 жыл бұрын
Thanks bhaiya
@aayush5474
@aayush5474 3 жыл бұрын
bro make one video on segmented sieve
@funenjoynilaypatel4553
@funenjoynilaypatel4553 2 жыл бұрын
31 march 2022. 9:00 am
@shridharsarraf2188
@shridharsarraf2188 3 жыл бұрын
Luv bhai❤
@harry-ns3wh
@harry-ns3wh 2 жыл бұрын
in que of monk we have to find minimum amount demanded by monk to god of money so what we can do here let the price of bicycle is P and initially he demand for 1 rupees from god next day amount will be double then double again and again by his father we want exactly how much money he demand from god so that he reach to his goal so what we will do here after each double we will check whether the doubled amount is less the cost price we again double this cycle continues upto when the amount is greater or equal to P if amount is greater at iteration "n" then take "n-1" iteration and subtract in from P so that particular amount and plus one rupees he demand from god if P is equal to any iteration then the amount is 1 demanded from god
@AmanKumarSinhaOfficial
@AmanKumarSinhaOfficial 3 жыл бұрын
Please Upload a video daily...
@wolfrikz7238
@wolfrikz7238 3 жыл бұрын
You're amazing
@prafullashukla9823
@prafullashukla9823 2 жыл бұрын
Sir,i am not able to understand the last part of code
@ankur_6174
@ankur_6174 3 жыл бұрын
Bhaya, aapne koi dsa sheet follow ki thi kya ? Aapne khud ki dsa sheet banane ki sochi hai ?
@jhashivam28
@jhashivam28 3 жыл бұрын
Bhaiya me Java mn yh follow krskta hu na.... CP playlist
@saurabhm1102
@saurabhm1102 3 жыл бұрын
bhaiya..combinatorics is missing in number theory.
@akshatawasthi5277
@akshatawasthi5277 6 ай бұрын
in second question, a simple solution would be like since we know if a^b=c, then c^b=a, so through this we can solve by running loop from 1 to n-1, and calculating the maximum as for(int i=1;i
@manoor0858
@manoor0858 Ай бұрын
wowwww thats so easy im so dumbbb
@aashitAgrawal
@aashitAgrawal Жыл бұрын
Here is my optimized solution #include using namespace std; int main() { long long n; cin >> n; long long a = 0, b = 0; long long count = 0; long long temp = n; while (temp != 0) { temp /= 2; count++; } // cout
@samagrapathak3854
@samagrapathak3854 3 жыл бұрын
Bhaia aap to bolre the ki aab graph aaega
@Sonalisingh3
@Sonalisingh3 3 жыл бұрын
Have you done all your exams of placements in C++ itself?? I want to know that is C++ is enough for off campus placements coding as well as interview or there should be any other programming languages also??
@iamluv
@iamluv 3 жыл бұрын
c++ is more than enough, for object oriented i personally prefer java
@Sonalisingh3
@Sonalisingh3 3 жыл бұрын
@@iamluv thank you for reply...but I want to know that only C++ is enough for job also or one more language should be there
@iamluv
@iamluv 3 жыл бұрын
@@Sonalisingh3 there is no generic answer to this, for placement c++ is enough, for working companies no language is enough, each company works with different stack, most of the people learn when they join in the process
@sahilharad9222
@sahilharad9222 3 жыл бұрын
@@iamluv but I think java is easy for me can I continue with java
@AmanKumarSinhaOfficial
@AmanKumarSinhaOfficial 3 жыл бұрын
@@iamluv Please upload one video daily...
@অবহেলাজীবন-য৪ব
@অবহেলাজীবন-য৪ব 3 жыл бұрын
Hello mujhe free fire hack auto headshot confi file do na please 1 file de do na
@mashapoguajay3322
@mashapoguajay3322 3 жыл бұрын
U r from iiita
@p38_amankuldeep75
@p38_amankuldeep75 2 жыл бұрын
❤💙❤
@tiger7858
@tiger7858 11 ай бұрын
4:02 "god se" 😅 nathuram godse
@e.m.hasanprince4609
@e.m.hasanprince4609 3 жыл бұрын
First comment
@grandparick3176
@grandparick3176 3 жыл бұрын
Who is more talented Luv or kunal kushwaha?
@randomshorts2820
@randomshorts2820 3 жыл бұрын
Luv
@manikantasai6118
@manikantasai6118 3 жыл бұрын
Who is kunal?
@rishabh507
@rishabh507 3 жыл бұрын
Bhai idhar padhne aaya hai ki comparison krne ?
@shridharsarraf2188
@shridharsarraf2188 3 жыл бұрын
Anyday luv bhai. Wo kunal egoist ko luv bhai se mat compare kar😏
@grandparick3176
@grandparick3176 3 жыл бұрын
@@shridharsarraf2188 a tune Sahi kaha bhai. Kunal larka talented ha but ego jeda ha.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Solve This Coding Problem and Win $200
8:06
Kenny Gunderman
Рет қаралды 2,4 МЛН
Unlocking Your Intuition: How to Solve Hard Problems Easily
17:34
Colin Galen
Рет қаралды 1,4 МЛН
Power Set | Bit Manipulation | DSA Sheet
10:58
Yogesh & Shailesh (CodeLibrary)
Рет қаралды 9 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 845 М.
Hardy's Integral
13:47
Michael Penn
Рет қаралды 17 М.
2 Years Of Learning C | Prime Reacts
22:24
ThePrimeTime
Рет қаралды 324 М.