Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #define ll long long
- #define pll pair<ll, ll>
- using namespace std;
- struct Params {
- ll width;
- ll height;
- ll classIndex;
- };
- ll n, k, m;
- ll w, h;
- vector<Params> classes;
- ll len(ll width1, ll height1, ll width2, ll height2) {
- return max(abs(width1 - width2), abs(height1 - height2));
- }
- vector<pll> distance(ll width, ll height) {
- vector<pll> result;
- for (auto cls : classes) {
- ll d = len(cls.width, cls.height, width, height);
- result.emplace_back(d, cls.classIndex);
- }
- sort(result.begin(), result.end());
- return result;
- }
- ll classif(vector<pll> dist, ll n) {
- if (k > dist.size()) k = dist.size();
- vector<pll> nearest(dist.begin(), dist.begin() + k);
- ll counter = 0;
- while (k + counter < dist.size() && nearest.back().first == dist[k + counter].first) {
- nearest.push_back(dist[k + counter]);
- counter++;
- }
- vector<ll> counts(n + counter, 0);
- for (auto neighbor : nearest) {
- if (neighbor.second < counts.size()) {
- counts[neighbor.second]++;
- }
- }
- return max_element(counts.begin(), counts.end()) - counts.begin();
- }
- int main() {
- cin >> n >> k >> m;
- for (ll i = 0; i < n; i++) {
- cin >> w >> h;
- classes.push_back({ w, h, i });
- }
- vector<ll> nums;
- for (ll i = 0; i < m; i++) {
- cin >> w >> h;
- ll ind = classif(distance(w, h), n + i);
- nums.push_back(ind + 1);
- classes.push_back({ w, h, ind });
- }
- for (ll i = 0; i < nums.size(); i++) {
- cout << nums[i];
- if (i < nums.size() - 1) cout << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement