-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleihuo1.cpp
93 lines (82 loc) · 1.55 KB
/
leihuo1.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
// global const
enum {
WIDTH = 3840,
HEIGHT = 2160
};
struct Pos
{
int x;
int y;
Pos(int xx, int yy): x(xx), y(yy)
{
}
};
struct Window
{
int id;
Pos point;
int width;
int height;
Window(int idx, int x, int y, int w, int h)
: id(idx), point(x, y), width(w), height(h)
{
}
};
bool IsInWindow(const Window& w, const Pos& p)
{
int left = w.point.x;
int right =
(left + w.width < WIDTH) ? (left + w.width) : WIDTH-1;
int top = w.point.y;
int bot =
(top + w.height < HEIGHT) ? (top + w.height) : HEIGHT-1;
if (p.x >= left && p.x <= right)
{
if (p.y >= top && p.y <= bot)
return true;
}
return false;
}
int ClickWhich(vector<Window>& windows, const Pos& click)
{
for (int i = windows.size() - 1; i >= 0; --i)
{
if (IsInWindow(windows[i], click))
{
int ret = windows[i].id + 1;
windows.push_back(windows[i]);
windows.erase(windows.begin() + i);
return ret;
}
}
return -1;
}
int main()
{
int num_open_windows, num_clicks;
cin >> num_open_windows >> num_clicks;
// read windows
vector<Window> windows;
for (int i = 0, x,y,w,h; i != num_open_windows; ++i)
{
cin >> x >> y >> w >> h;
windows.emplace_back(i, x, y, w, h);
}
// read clicks
vector<Pos> clicks;
for (int i = 0, x,y; i != num_clicks; ++i)
{
cin >> x >> y;
clicks.emplace_back(x, y);
}
// io done
for (auto &e : clicks)
{
cout << ClickWhich(windows, e) << endl;
}
return 0;
}