diff --git a/theory/data_structure/arrays.cpp b/theory/data_structure/arrays.cpp new file mode 100644 index 0000000..9683168 --- /dev/null +++ b/theory/data_structure/arrays.cpp @@ -0,0 +1,31 @@ +#include + +//Reverse an array +void reverseArray(int *v, int size) { + + int tmp, a = 0; + for(int i = size-1; i>=size/2; --i) { + tmp = v[i]; + v[i] = v[a]; + v[a] = tmp; + a++; + } + +} + +int main(){ + + int arr[] = {0,1,2,3,4,5,6,7,8,9}; + int n = 10; + reverseArray(arr, n); + +} + + + + + + + + + diff --git a/theory/greedy/busyman.cpp b/theory/greedy/busyman.cpp new file mode 100644 index 0000000..f3f61bb --- /dev/null +++ b/theory/greedy/busyman.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + + +// Creating a template to sort the vector of pairs +// using the second int element +bool sortbysec(const std::pair &a, const std::pair &b) { + return (a.second < b.second); +} + +// function to count the max of activites that we can make +// Picking the first, after sorting te vector, to use as base +int findMax(std::vector> v) { + + std::sort(v.begin(),v.end(),sortbysec); + + int count = 1, temp = v[0].second; + for(int i = 1; i < v.size(); ++i) { + if(v[i].first >= temp && v[i].second > temp) { + count++; + temp = v[i].second; + } + } + + return count; + +} + +int main(){ + + + std::vector> act; + int n, t; + std::cin >> n; + + for(int i = 0; i < n; ++i) { + + std::cin >> t; + for(int j = 0; j < t; ++j) { + int s, e; + std::cin >> s >> e; + act.emplace_back(std::make_pair(s,e)); + } + + int count = findMax(act); + std::cout << count << std::endl; + + } + +} + + diff --git a/theory/greedy/indianCoinChange.cpp b/theory/greedy/indianCoinChange.cpp new file mode 100644 index 0000000..75d53a0 --- /dev/null +++ b/theory/greedy/indianCoinChange.cpp @@ -0,0 +1,59 @@ +/* + + Problem: Suposse you want to make a change of some + Indian Rupees using minimum number of coins / notes + + Denominatios = [1,2,5,10,20,50,100,500,2000] + + + Input + 273 + + Output + 100+100+50+20+2+1 + +*/ + +#include +#include +#include + +std::vector denomination = {1,2,5,10,20,50,100,500,2000}; + + +void findMin(int n) { + + std::vector ans; + + for(int i = denomination.size()-1; i >= 0; --i) { + + while(n >= denomination[i]) { + n -= denomination[i]; + ans.push_back(denomination[i]); + } + } + + + for(auto x: ans) + std::cout << x << " "; + std::cout << std::endl; + +} + + +int main(){ + + int n; + std::cin >> n; + + findMin(n); + + +} + + + + + + +