Codeforces Round #608 (Div. 2) C. Shawarma Tent

链接:

https://codeforces.com/contest/1271/problem/C

题意:

The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.

The main school of the capital is located in (sx,sy). There are n students attending this school, the i-th of them lives in the house located in (xi,yi). It is possible that some students live in the same house, but no student lives in (sx,sy).

After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the i-th student goes from the school to his house is |sx−xi|+|sy−yi|.

The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the i-th student will buy a shawarma if at least one of the shortest paths from the school to the i-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).

You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.’

思路:

枚举终点上下左右四个方向计算

代码:

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2e5+10;

pair<int, int> po[MAXN];
int n, x, y;

int main()
{
    cin >> n >> x >> y;
    for (int i = 1;i <= n;i++)
        cin >> po[i].first >> po[i].second;
    int v[4] = {0, 0, 0, 0};
    int mv = 0;
    for (int i = 1;i <= n;i++) if (po[i].second > y)
        v[0]++;
    mv = max(mv, v[0]);
    for (int i = 1;i <= n;i++) if (po[i].first > x)
        v[1]++;
    mv = max(mv, v[1]);
    for (int i = 1;i <= n;i++) if (po[i].second < y)
        v[2]++;
    mv = max(mv, v[2]);
    for (int i = 1;i <= n;i++) if (po[i].first < x)
        v[3]++;
    mv = max(mv, v[3]);
    cout << mv << endl;
    if (mv == v[0])
        cout << x << ' ' << y+1 << endl;
    else if (mv == v[1])
        cout << x+1 << ' ' << y << endl;
    else if (mv == v[2])
        cout << x << ' ' << y-1 << endl;
    else
        cout << x-1 << ' ' << y << endl;

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/YDDDD/p/12089060.html
今日推荐