File tree 2 files changed +74
-0
lines changed
2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ You have been given an undirected graph consisting of N nodes and M
3
+ edges. This graph can consist of self-loops as well as multiple edges.
4
+ In addition , you have also been given Q queries. For each query , you
5
+ shall be given 2 integers A and B. You just need to find if there exists
6
+ an edge between node A and node B. If yes, print "YES" (without quotes)
7
+ else , print "NO"(without quotes).
8
+
9
+ */
10
+ #include < iostream>
11
+ using namespace std ;
12
+ int arr[1000 ][1000 ];
13
+ void initialize (){
14
+ for (int i = 0 ; i < 1000 ; i++){
15
+ for (int j = 0 ; j < 1000 ; j++){
16
+ arr[i][j] = false ;
17
+ }
18
+ }
19
+ }
20
+ int main (){
21
+
22
+ int x,y,n,m,q;
23
+ initialize ();
24
+ cin >> n >> m;
25
+ for (int i = 0 ; i < m; i++){
26
+ cin >> x >> y;
27
+ arr[x][y] = true ;
28
+ }
29
+ cin >> q;
30
+ for (int i = 0 ; i < q; i ++){
31
+ cin >> x >> y;
32
+ if (arr[x][y]== true ){
33
+ cout << " YES" <<" \n " ;
34
+ }else {
35
+ cout << " NO" <<" \n " ;
36
+ }
37
+ }
38
+ return 0 ;
39
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ You are given container full of water. Container can have limited amount
3
+ of water. You also have N bottles to fill. You need to find the maximum
4
+ numbers of bottles you can fill.
5
+ */
6
+ #include < iostream>
7
+ #include < algorithm>
8
+ using namespace std ;
9
+ const int MAX = 100000 ;
10
+ int A[MAX];
11
+ int main (){
12
+ int T;
13
+ cin >> T;
14
+ while (T--){
15
+
16
+ int N,Capacity;
17
+ cin >> N >> Capacity;
18
+ int numberBottles = 0 , numberOfBottles = 0 ;
19
+ for (int i = 0 ; i < N; i++){
20
+ cin >> A[i];
21
+ }
22
+ sort (A,A+N);
23
+ for (int i = 0 ; i < N; i++){
24
+ numberBottles += A[i];
25
+ if (numberBottles > Capacity){
26
+ break ;
27
+ }else {
28
+ numberOfBottles++;
29
+ }
30
+ }
31
+ cout << numberOfBottles << " \n " ;
32
+
33
+ }
34
+ return 0 ;
35
+ }
You can’t perform that action at this time.
0 commit comments