「题解」Luogu 2038「无线网络发射器选址」

分析

又是一道傻x模拟,很好做的

代码

#include<cstdio>
#include<algorithm>
const int MAXN = 20 + 6;
struct Point{
    int x,y,k;
    Point(){}
    Point(int x,int y,int k){
        this -> x = x;
        this -> y = y;
        this -> k = k;
    }
};Point P[MAXN];

int main(){
    int d,n,max = 0,cnt = 0,delta = 0;scanf("%d\n%d",&d,&n);
    for(int i = 1;i <= n;i++) scanf("%d %d %d",&P[i].x,&P[i].y,&P[i].k);
    for(int i = 0;i < 129;i++){
        for(int j = 0;j < 129;j++){
            delta = 0;
            for(int k = 1;k <= n;k++){
                if(P[k].x >= i - d && P[k].x <= i + d && P[k].y >= j - d && P[k].y <= j + d){
                    delta += P[k].k;
                }
            }
            if(max == delta){cnt++;}
            if(max < delta){
                cnt = 1;
                max = delta;
            }
        }
    }
    printf("%d %d",cnt,max);

    return 0;
}