标签:als 矩形 std vector 并且 str struct 选择 end
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int N = 10 + 5; 6 7 struct Rect{int x1, y1, x2, y2, z, num; }; 8 9 vector<Rect> v; 10 int n, m; 11 12 bool isInse(Rect x, Rect y) { 13 int xIn = min(x.x2, y.x2) - max(x.x1, y.x1); 14 int yIn = min(x.y2, y.y2) - max(x.y1, y.y1); 15 return (xIn >= 0 && yIn >= 0)? true: false; 16 } 17 18 bool inArea(Rect t, int x, int y) { 19 if(x >= t.x1 && x <= t.x2 && y >= t.y1 && y <= t.y2) return true; 20 return false; 21 } 22 23 void print_v() { 24 for(auto &i : v) { 25 printf("x1: %d, y1: %d, x2: %d, y2: %d, z:%d, num: %d\n", i.x1, i.y1, i.x2, i.y2, i.z, i.num); 26 } 27 } 28 29 int find_top(int x, int y) { 30 for(int i = n - 1; i >= 0; i--) { 31 if(inArea(v[i], x , y)) return i; 32 } 33 return -1; 34 } 35 36 void move_top(int pos) { 37 Rect tmp = v[pos]; 38 v.erase(v.begin() + pos); 39 int maxz = 0; 40 for(int i = 0; i < n - 1; i++) { 41 maxz = max(maxz, v[i].z); 42 } 43 tmp.z = maxz + 1; 44 v.push_back(tmp); 45 } 46 int main() { 47 cin >> n >> m; 48 for(int i = 0; i < n; i++) { 49 Rect tmp; 50 cin >> tmp.x1 >> tmp.y1 >> tmp.x2 >> tmp.y2; 51 tmp.z = 0, tmp.num = i + 1; 52 for(int j = i - 1; j >= 0; j --) { 53 if(isInse(v[j], tmp)) { 54 tmp.z = v[j].z + 1; 55 break; 56 } 57 } 58 v.push_back(tmp); 59 } 60 //print_v(); 61 int x, y; 62 for(int i = 0; i < m; i++) { 63 cin >> x >> y; 64 int pos = find_top(x, y); 65 if(pos == -1) cout << "IGNORED" << endl; 66 else { 67 printf("%d\n", v[pos].num); 68 move_top(pos); 69 } 70 } 71 }
标签:als 矩形 std vector 并且 str struct 选择 end
原文地址:https://www.cnblogs.com/Pretty9/p/11427606.html