Luo Gu P2038 wireless network transmitter site

Title Description

With the growing popularity of smart phones, the demand for wireless networks is increasing. A city decision in public places in the city wireless network coverage.

Suppose the city layout strictly parallel by a \ (129 \) east-west and the street (129 \) \ lattice formed by the north-south street, and the distance between adjacent parallel streets are constant $ 1 $. East-west streets from north to south are numbered \ (0,1,2 ... 128 \) and \ (0,1,2 ... 128 \) , north-south streets are numbered from west to east as $ 0 2 ... $ 128.

And north-south east-west streets intersecting to form a street intersection, the provisions of numbered \ (x \) north and south of the street and the number \ (y \) coordinates of the intersection of the east-west streets that form $ (x, y) $. There is a certain number of public places in certain intersection.

As the government financial problems, can only install a large wireless network transmitter. Reach the wireless network transmitter is a point in the center, a side length of a square $ $ 2D. Reach including square boundary.

Now the government departments concerned are ready to install a wireless network transmitter propagation parameters for the $ d $, I hope you help them find the right intersection as the installation site, making the most public places in the city covered.

Input Format

The first row contains an integer $ d $, represents the propagation distance of wireless network transmitter.

The second row contains an integer \ (n-\) , expressed in the number of intersections in public places.

Next n lines, each line is given three integers X $, Y, K, \ (separated by a space, the coordinates of intersection represent \) number of (x, y) $ junction and public places. The same coordinates will be given once.

Output Format

An output line, comprising two integers, separated by a space, and the number of public places can cover up the number of program installation site can cover up in public places, respectively.

Sample input and output

Input # 1 replication

1
2
4 4 10
6 6 20

Copy Output # 1

1 30

Description / Tips

对于\ (100% \)的数据, \ (1 \ leq d \ leq 20, 1 \ leq n \ leq 20,0 \ leq x \ leq 128 0 \ leq y \ leq 128, 0 <k \ leq 1000000 , 1≤d≤20,1≤n≤20,0≤x≤128,0≤y≤128,0 <k≤1000000 \)

Resolution:

OnesimpleThe simulation questions.

Because it is \ (129 \ times 129 \) of the square, so we can enumerate each point

Then the center point can be the starting point for four weeks and sweep accumulated

We had to record two variables,

\ (NUM \) the number of the maximum recording, \ (ANS \) records a maximum value,

One obvious conclusion is that there is

We replaced the maximum time you can put Replace num 1

This value is the same or larger number will later.

Emotional understanding.

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#define re register
#define Max 130
int n,ans = 0,d,g[Max][Max],num;
inline void init() {
    scanf("%d%d",&d,&n);int x,y,k;
    for(re int i = 1 ; i <= n ; ++ i)
        scanf("%d%d%d",&x,&y,&k),g[x][y] = k;
}
void work() {
    int max_place;
    for(re int i = 0 ; i <= 128 ; ++ i)
        for(re int j = 0 ; j <= 128 ; ++ j) {
            max_place = 0;
            for(re int a = -d ; a <= d ; ++ a)
                for(re int b = -d ; b <= d ; ++ b)
                    if(a + i >= 0 && a + i <= 128 && b + j <= 128 && b + j >= 0)//判断边界情况
                        max_place += g[a+i][b+j];
        if(max_place == ans) num++;
        if(max_place > ans) ans = max_place, num = 1;
        }
}
inline void print() {printf("%d %d",num,ans);}
int main() {
    init();
    work();
    print();
    return 0;
}

Guess you like

Origin www.cnblogs.com/handsomegodzilla/p/11442907.html