zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    FpSpread实现筛选的功能
    比较通用的ID,ParentID结构表,返回树路径。
    如何解决,在安装Sql2000时,出现程序挂起的解决方法。
    FarPoint Spread 控件如何实现剪切,粘贴,复制
    MySql中Group By和Order By使用的注意事项!
    php md5下16位和32位的实现代码
    Shadows在C#代替方法!
    FTP命令使用详解
    数据库中存放目录与文件结构,方案选择
    vs2008 sp1下载
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12089060.html
Copyright © 2011-2022 走看看