跳到正文

题解

P2038 Solution

#SUSPENDED#约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年12月31日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 2 分钟
获赞
4
题目
P2038

版本

  1. v1当前

题目传送门

抢个题解求过啊!


我们用两重循环遍历所有可能的路口作为安装点,然后对于每个可能的安装点,再用一重循环遍历所有有公共场所的路口,并检查是否在传播范围内,如果在则累加公共场所数量,然后更新答案,最后输出。

C++
#include <iostream>
using namespace std;

int a[25][5];

int main()
{
    int d, n;
    cin >> d >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            cin >> a[i][j];
    int cnt = 0, ans = 0;
    for (int i = 0; i <= 128; i++)
        for (int j = 0; j <= 128; j++)
        {
            int pos = 0;
            for (int k = 1; k <= n; k++)
                if (abs(a[k][1] - i) <= d && abs(a[k][2] - j) <= d)
                    pos += a[k][3];
            if (pos > ans)
            {
                ans = pos;
                cnt = 1;
            }
            else if (pos == ans) cnt++;
        }
    cout << cnt << " " << ans;
    return 0;
}
原文
存档评论4 条抓取于