-
Notifications
You must be signed in to change notification settings - Fork 24
/
CircleMarket.cpp
46 lines (42 loc) · 999 Bytes
/
CircleMarket.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
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
using namespace std;
class CircleMarket {
public:
int makePurchases(vector <int> open, vector <int> close, int travel) {
int t = 0;
int pur = 0;
int i = 0;
bool mark[100];
memset(mark, 0, sizeof(mark));
int m = 0;
for (int j = 0; j < close.size(); ++j)
m = max(close[j], m);
while (t <= m)
{
if (t >= open[i] && t <= close[i] && !mark[i])
{
mark[i] = true;
++pur;
}
i = (i+1)%open.size();
t += travel;
}
return pur;
}
};