-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment_3.cpp
76 lines (74 loc) · 1.38 KB
/
assignment_3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Q1)
#include <bits/stdc++.h>
using namespace std;
int denomination(int n)
{
vector<int> v = {1, 5, 10};
int count = 0;
while (n)
{
for (int i = v.size() - 1; i >= 0; i--)
{
int total = 0;
if (v[i] > n)
{
continue;
}
else
{
total = n / v[i];
n -= total * v[i];
count += total;
}
}
}
return count;
}
int main()
{
int n;
cin >> n;
cout << denomination(n);
return 0;
}
Q2)
int refills(int dist, int capacity, int stops, vector<int> v)
{
int count = 0;
int travelled = 0;
int d = 0;
for (int i = 1; i < stops + 1; i++)
{
if (v[i] - v[i - 1] > capacity)
{
return -1;
}
}
while (d < dist)
{
for (int i = 0; i < stops + 1; i++)
{
if (v[i] - travelled > capacity)
{
count += 1;
travelled = v[i - 1];
d = travelled;
i -= 1;
}
}
if (v[stops] - v[stops - 1] < capacity)
{
break;
}
}
return count;
}
int main()
{
// int n;
// cin >> n;
// cout << denomination(n);
vector<int> v = {200, 375, 550, 750, 950};
cout << refills(950, 400, 4, v);
return 0;
}