无线网络发射器选址

传送门:https://www.luogu.org/problemnew/show/P2038#sub

因为数据范围很小,暴力模拟即可:依次枚举每个点是放无线网络发射器的位置,再依次统计能覆盖的公共场所数目。

#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long int
int d,n,tot;
ll sum,ans;
struct node
{
    int x,y;
    ll k;
}t[20];
int main()
{
    scanf("%d%d",&d,&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d%d%lld",&t[i].x,&t[i].y,&t[i].k);
    }
    for(int i = 0;i <= 128;i++)
    {
        for(int j = 0;j <= 128;j++)
        {
            sum = 0;
            for(int m = 1;m <= n;m++)
            {
                if(abs(t[m].x - i) <= d && abs(t[m].y - j) <= d)
                {
                    sum += t[m].k;
                }
            }
            if(sum > ans)
            {
                tot = 1;
                ans = sum;
            }
            else if(sum == ans)
            {
                tot++;
            }
        }
    }
    printf("%d %lld",tot,ans);
    return 0;
}
原文地址:https://www.cnblogs.com/peppa/p/9887995.html