-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path497.cpp
More file actions
28 lines (26 loc) · 788 Bytes
/
497.cpp
File metadata and controls
28 lines (26 loc) · 788 Bytes
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
class Solution {
vector<vector<int>> rectangles;
vector<int> area;
public:
Solution(vector<vector<int>>& rects) {
rectangles = rects;
int cum_area = 0;
for(auto& r: rectangles){
cum_area += (r[2]-r[0]+1)*(r[3]-r[1]+1);
area.push_back(cum_area);
}
}
vector<int> pick() {
int rand_area = rand()%area.back();
int idx = upper_bound(area.begin(),area.end(),rand_area) - area.begin();
auto r = rectangles[idx];
int x = rand() % (r[2]-r[0]+1) + r[0];
int y = rand() % (r[3]-r[1]+1) + r[1];
return {x,y};
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(rects);
* vector<int> param_1 = obj->pick();
*/