-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98b28f0
commit fa49686
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <iostream> | ||
|
||
//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); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
|
||
// Creating a template to sort the vector of pairs | ||
// using the second int element | ||
bool sortbysec(const std::pair<int,int> &a, const std::pair<int,int> &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<std::pair<int, int>> 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<std::pair<int, int>> 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; | ||
|
||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
std::vector<int> denomination = {1,2,5,10,20,50,100,500,2000}; | ||
|
||
|
||
void findMin(int n) { | ||
|
||
std::vector<int> 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); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|