Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- struct park
- {
- ll x1, y1, x2, y2;
- };;
- ll n, m, k, r, c, c1, c2, c3, c4, ans, ans1, ans2;
- park xp[105], yp[105];
- ll in(ll x11, ll x12, ll x21, ll x22)
- {
- //cout << "sdf " << x11 << " " << x12 << " " << x21 << " " << x22 << "\n";
- x11 = max(x11, x21);
- x12 = min(x12, x22);
- if(x12 - x11 + 1 >= 0)
- return (x12 - x11 + 1);
- return 0;
- }
- void inter(ll x1, ll y1, ll x2, ll y2)
- {
- ll cur = 0;
- if(x1 >= 1 && x1 <= n && x2 >= 1 && x2 <= n && y1 >= 1 && y1 <= m && y2 >= 1 && y2 <= m)
- {
- for(int i = 1; i <= k; i++)
- {
- cur += in(x1, x2, xp[i].x1, xp[i].x2) * in(y1, y2, xp[i].y1, xp[i].y2);
- }
- //cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << cur << "\n";
- if(cur < ans)
- {
- ans1 = x1;
- ans2 = y1;
- ans = cur;
- }
- if(cur == ans)
- {
- if(x1 < ans1)
- {
- ans1 = x1;
- ans2 = y1;
- }
- if(x1 == ans1)
- {
- if(y1 < ans2)
- {
- ans1 = x1;
- ans2 = y1;
- }
- }
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- ans = 9999999999999;
- cin >> n >> m >> k >> r >> c;
- xp[0] = {0, 0, 0, m + 1};
- xp[k + 1] = {n + 1, 0, n + 1, m + 1};
- yp[0] = {1, 0, n, 0};
- yp[k + 1] = {1, m + 1, n, m + 1};
- for(int i = 1; i <= k; i++)
- {
- cin >> c1 >> c2 >> c3 >> c4;
- yp[i] = xp[i] = {c1, c2, c3, c4};
- }
- for(int i = 0; i <= k + 1; i++)
- {
- for(int j = 0; j <= k + 1; j++)
- {
- ll x1 = 0, x2 = 0, y1 = 0, y2 = 0;
- x2 = xp[i].x1 - 1;
- x1 = x2 - r + 1;
- y2 = yp[j].y1 - 1;
- y1 = y2 - c + 1;
- inter(x1, y1, x2, y2);
- x1 = xp[i].x2 + 1;
- x2 = x1 + r - 1;
- y2 = yp[j].y1 - 1;
- y1 = y2 - c + 1;
- inter(x1, y1, x2, y2);
- x2 = xp[i].x1 - 1;
- x1 = x2 - r + 1;
- y1 = yp[j].y2 + 1;
- y2 = y1 + c - 1;
- inter(x1, y1, x2, y2);
- x1 = xp[i].x2 + 1;
- x2 = x1 + r - 1;
- y1 = yp[j].y2 + 1;
- y2 = y1 + c - 1;
- inter(x1, y1, x2, y2);
- }
- }
- cout << ans1 << " " << ans2 << " " << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement