Skip to main content

Posts

Showing posts with the label Greedy

Maximum Number of Coins You Can Get (LeetCode)

Problem Name: 1561.  Maximum Number of Coins You Can Get Problem Link: https://leetcode.com/problems/maximum-number-of-coins-you-can-get/description/ Difficulty: Medium Tag: Sorting | Array | Math | Greedy | Sorting | Game theory Language: C# | C++ OJ: LeetCode Algorithm: Sort the Piles: Sort the array of piles in descending order, so that the piles with the maximum number of coins are at the beginning. Calculate the Total Number of Piles to Collect From: Determine the total number of piles you can collect coins from based on the rule that for every three consecutive piles, you can only pick coins from two of them. Set this value to 2/3 of the total number of piles. Iterate Through Piles and Collect Coins: Start iterating through the sorted piles from the second pile (index 1) and continue up to the calculated total number of piles to collect from. In each iteration, collect the coins from the current pile. Since you can only collect coins from every second pile, use a step of ...

Educational Codeforces Round 135 (Rated for Div. 2) (B. Best Permutation)

Bismillahir Rahmanir Rahim Bangla tutorial: https://www.youtube.com/watch?v=jJEXNroYls8&t=566s&ab_channel=AlgoBot ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is repr...

Technocup 2018 - Elimination Round 2 (C. Maximum splitting)

  Bismillahir Rahmanir Rahim 4  is the lowest composite number so we must think about  4  divisibility( 0 - 3 ) Case  1 : if  number  divided by  4  the it is  OK Case  2 :After dividing  4  the number it ' s reminder is  1  then        num= 1  output is (- 1 ).        num= 5  output is (- 1 ).        after that  number is  9  other is  4 .alike  13 = 9 + 4   21 = 9 + 4 + 4 + 4 Case  3 :After dividing  4  the number it ' s reminder is  2  then        num= 2  output is (- 1 ).        after that  number...

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) (B. Bash's Big Day)

  Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long  ...

Codeforces Round #806 (Div. 4) (F. Yet Another Problem About Pairs Satisfying an Inequality)

  Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> #include<sstream> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<map> #include<set> #include<stack> #include<vector> #include<iterator> #include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using namespace std; typedef long long ll; ll mod=1000000007; ll dx[] = { -2, -1, 1, 2, -2, -1, 1, 2 }; ll dy[] = { -1, -2, -2, -1, 1, 2, 2, 1 }; int main() {     ll tst,n;     cin>>tst;     while(tst--)     {       ...

Codeforces Round #764 (Div. 3) (C. Division by Two and Permutation)

  Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long  ...

Codeforces Round #630 (Div. 2) (A. Exercising Walk)

  Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long  ...

Codeforces Round #797 (Div. 3) (E. Price Maximization)

Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long   long ...

Codeforces Round #797 (Div. 3)(B. Array Decrements)

  Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long  ...

Codeforces Round #787 (Div. 3)(B. Make It Increasing)

  Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long  ...