• 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;
    }
    
  • 相关阅读:
    Android TP出现小圆点解决方法
    Android的SAFE MODE(安全模式)
    Linux TCP透传到OneNET
    C读取BMP数据
    OLED显示BMP数据
    电脑出现DNS错误无法上网怎么办
    办公室如果没有网络怎么办呢?
    微信扫一扫获取地理位置
    win10系统程序与功能查找,卸载程序
    手把手学习数据库
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12089060.html
Copyright © 2020-2023  润新知