• 3 days ago
Transcript
00:00In the code, I have my classroom class, it has a main function.
00:03I have n given which is my rows.
00:05I have m given which is equal to 6, that is my columns.
00:09I have cost, vertical.
00:11I have horizontal cost.
00:13Integer type, so that the sorting descending order will be easy.
00:17So, for this, I have the first job to sort my cost.
00:21I will write erase.sort
00:22First, cost, vertical.
00:25I will sort it in reverse order.
00:27Then, collections.reverseOrder
00:30After that, I will sort my horizontal cost.
00:34So, erase.sort
00:35My cost.horizontal
00:37I will sort it in reverse order.
00:40Then, collections.reverseOrder
00:43Now, I have both in descending order.
00:46Now, I will take my 4 variables.
00:48One will start with h, which will start with 0.
00:50One will start with v, which will start with 0.
00:52I will start with horizontal cut.
00:55I will start with vertical cut.
00:57Now, I will start with vertical cut.
00:58What will I do with this?
00:59I will take horizontal pieces.
01:00I will take horizontal pieces.
01:02Vertical pieces.
01:03I will take 0 to equal.
01:04Now, I will start with a loop.
01:06Until my h value is less than my cost of horizontal.length.
01:11And, when my v value is less than my cost of vertical.length.
01:16And, length.
01:18I will start with length.
01:19I will start with the entire arrays.
01:20I will start with traverse.
01:20Then, I will start with my loop.
01:21Now, I will compare.
01:24Which amount is less than my cost.
01:25First, my case will be in which vertical cost is less than horizontal cost.
01:30Which case will be in which way?
01:31If my cost of vertical of v is less than or equal to my cost of horizontal of h.
01:42Which case will be in which way?
01:44If the vertical cost is less than or horizontal cost is less than.
01:47Then, I will start with horizontal cut.
01:49Because, I will start with horizontal cut.
01:51First, I will start with horizontal cut.
01:56Here, I will start with horizontal cut.
02:00Horizontal cut.
02:01So, I will take a variable here.
02:03Final cost.
02:04I will take cost.
02:05Cost is equal to 0.
02:07Horizontal cut.
02:08Horizontal cut.
02:08I mean, how does cost increase?
02:11Cost will increase.
02:12What will cost of horizontal cut?
02:12Which will be my current cost.
02:14Cost of horizontal.
02:16H.
02:17Multiply by how many vertical pieces are.
02:19Because, vertical pieces will be through my horizontal cut.
02:24So, all the vertical pieces will be through horizontal cut.
02:28So, cut of horizontal cut, cost multiplied by vertical pieces.
02:33Cost will be added in the cost.
02:34Then, I will add.
02:34As the horizontal cut will be through horizontal cut.
02:36pieces plus plus हो जाएंगे क्योंकि horizontal cut लग गया तो एक और horizontal
02:40piece बन गया और मेरा hb plus plus हो जाएगा दूसरा इसका case होगा जिसमें
02:46मुझे vertical cut लगाना है vertical cut वाले case में my cost will be
02:52plus equal to इसमें मैं vertical cut लगाऊंगी तो cost of vertical v
02:56multiplied by my horizontal pieces क्योंकि horizontal अगर pieces हैं तो उनके
03:02through एक vertical cut जाएगा यानि उपर से नीचे वाली direction में तो उस सारे
03:06pieces के through जाएगा तो cost के अंदर add होगा vertical single cut का
03:10cost multiplied by total horizontal pieces अब मैं कर दूँगी अपने vertical
03:14pieces को plus plus क्योंकि एक और vertical piece add हो जाएगा और मैं कर दूँगी
03:18को plus plus बाद में मुझे क्या करना है कोई मेरे array के अंदर अभी रह गए
03:22हैं cuts तो मैं उनको apply कर दूँँ तो मैं एक loop जला दूँगी जब तक my h is less
03:27than
03:28my cost of horizontal dot length तब तक मैं सारे horizontal cuts को लगा दूँ
03:35horizontal cuts यानि in conditions को मैं यापर copy कर सकती हूँ
03:42and h plus plus तो यह हो जाएगा मेरा horizontal cut जितनी भी बच गए है
03:46ऐसे ही अगर कोई vertical cuts बच जाते हैं तो उनके भी एक loop लगा लेते हैं
03:51v is less than my cost of vertical dot length यहाँ पर हम इन vertical cuts वाली lines को
04:01copy कर लेंगे and paste finally क्या करना है मेरी जो final cost है वो इस cost की form में
04:08मेरे
04:08पास आ चुकी है और उसको मुझे print करवा देना है cost of
04:13यह इसको मैं कहे दू minimum cost of cuts is equal to cost इसको कर लेते हैं save
04:24इसको मैं हलका सा summarize करूँ तो मैंने पहले क्या किया अपने cost को मैंने
04:29sub को reverse order में sort कर दिया यह यह descending order में मैंने 5 variables लिये पहले वाले तो
04:34है horizontal
04:34vertical pointers फिर है मेरे पास horizontal pieces and vertical pieces का count फिर मेरे पास है cost
04:40इस horizontal pieces को शुरुआत में मुझे रखना है one and vertical pieces को भी शुरुआत में रखना है one
04:45क्योंकि मेरे पास single piece है horizontal में भी उतन ही है vertical में भी उतन ही है
04:49मुझे क्या करना है एक loop चलाना है जब तक मैं अपने पूरे horizontal cuts and पूरे vertical cuts वाले
04:55array को traverse नहीं कर लेती है
04:56अगर horizontal cut की cost ज्यादा है तो फिर मुझे horizontal cut लगाना है कैसे cut लगाने का मतलब है
05:03cost के अंधर तो मैं add कर दूँ उस horizontal cut की cost multiplied by कितने vertical pieces को वो
05:08cut कर रहा है
05:09और फिर मैं horizontal pieces को कर दूं plus plus H को कर दूं plus plus
05:13If it is a vertical cut, then how many horizontal pieces will vertically cut the line?
05:19The cost is multiplied by my total horizontal pieces
05:22Here I have done vertical pieces plus plus and we have done plus plus
05:25After that, there will be some horizontal cuts, I have done it in chocolate
05:29Vertical cuts will also count the cost
05:32Last month, I will print my cost
05:34Let's do this, save and run
05:39The final answer I have is minimum cost of my cuts which is equal to 42
05:43Which you have already seen in very detail dry run
05:46How much of these cuts will be 42
05:49So in this way, we will solve the chocolate problem
05:52If you want, then go to the same code
05:56Spodge is a platform
05:58This is a platform SPOJ
06:00Here is the name of chocolate problem
06:03You can go and submit here
06:06The code will work properly
06:07And sometimes in your interview
06:10There will be a little changed version of this problem
06:14That is why you have to understand logic problems
06:16So if you have problems
06:19If you have a square board
06:20Or a board
06:23Or a board
06:23Or you have a chocolate
06:24Or you have a place in chocolate
06:25Or you have to change something else
06:27If you have to cut the chess board
06:29To cut the chess board
06:30So in that case, there are 64 pieces of chess board
06:33So here
06:34The value of N will be 8
06:35And M will be 8
06:36But you have to keep the same code
06:38Under the same code
06:38Under the same code
06:39So in this way, we solve the chocolate problem
06:42And for its related problems
06:43We apply the same logic
06:44To the same logic
06:45For the same logic
06:45We apply the same logic