forked from Kvaibhav01/HackerEarth-Solutions
-
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.
Merge pull request Kvaibhav01#5 from CruiseDevice/master
some of the solutions for algorithms problem from hackerearth
- Loading branch information
Showing
2 changed files
with
74 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,39 @@ | ||
/* | ||
You have been given an undirected graph consisting of N nodes and M | ||
edges. This graph can consist of self-loops as well as multiple edges. | ||
In addition , you have also been given Q queries. For each query , you | ||
shall be given 2 integers A and B. You just need to find if there exists | ||
an edge between node A and node B. If yes, print "YES" (without quotes) | ||
else , print "NO"(without quotes). | ||
*/ | ||
#include <iostream> | ||
using namespace std; | ||
int arr[1000][1000]; | ||
void initialize(){ | ||
for(int i = 0; i < 1000; i++){ | ||
for(int j = 0; j < 1000; j++){ | ||
arr[i][j] = false; | ||
} | ||
} | ||
} | ||
int main(){ | ||
|
||
int x,y,n,m,q; | ||
initialize(); | ||
cin >> n >> m; | ||
for(int i = 0 ; i < m; i++){ | ||
cin >> x >> y; | ||
arr[x][y] = true; | ||
} | ||
cin >> q; | ||
for(int i = 0; i < q; i ++){ | ||
cin >> x >> y; | ||
if(arr[x][y]== true){ | ||
cout << "YES"<<"\n"; | ||
}else{ | ||
cout << "NO"<<"\n"; | ||
} | ||
} | ||
return 0; | ||
} |
35 changes: 35 additions & 0 deletions
35
Algorithms/C++/Greedy Algorithms/Being_greedy_for_water.cpp
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,35 @@ | ||
/* | ||
You are given container full of water. Container can have limited amount | ||
of water. You also have N bottles to fill. You need to find the maximum | ||
numbers of bottles you can fill. | ||
*/ | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
const int MAX = 100000; | ||
int A[MAX]; | ||
int main(){ | ||
int T; | ||
cin >> T; | ||
while(T--){ | ||
|
||
int N,Capacity; | ||
cin >> N >> Capacity; | ||
int numberBottles = 0, numberOfBottles = 0; | ||
for(int i = 0; i < N; i++){ | ||
cin >> A[i]; | ||
} | ||
sort(A,A+N); | ||
for(int i = 0; i < N; i++){ | ||
numberBottles += A[i]; | ||
if(numberBottles > Capacity){ | ||
break; | ||
}else{ | ||
numberOfBottles++; | ||
} | ||
} | ||
cout << numberOfBottles << "\n"; | ||
|
||
} | ||
return 0; | ||
} |