Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1301
Because the number of lattice is much larger than that in the rat's Nest, the starting point of the rat's nest is to increase the "lattice value" in the D range around the rat's nest, and then scan the maximum lattice value of each lattice.
Complete code:
01./*0.125s*/02.
#include <bits/stdc++.h> 04.using namespace std;
05.const int MAXN = 1030;
07.int CNT[MAXN][MAXN]; 09.int Main () 10.
{one. int T, d, N, I, J, p, Q;
int x, y, num, Lmax;
int x_min, X_max, Y_min, Y_max;
scanf ("%d", &t); while (t--) 16.
{scanf ("%d%d", &d, &n);
memset (CNT, 0, sizeof (CNT)); for (i = 0; i < n; ++i) 20.
{scanf ("%d%d%d", &x, &y, &num);
x_min = max (0, x-d), X_max = min (1024, x + D);
y_min = max (0, y-d), Y_max = min (1024, y + D); for (p = x_min p <= x_max; ++p) 25. for (q = y_min q <= y_max; ++q) 26.
CNT[P][Q] + = num; 27.} 28.
Lmax = x = y = 0; for (i = 0; i < 1025 ++i) 30. for (j = 0; J < 1025 ++j) 31. if (Cnt[i][j] > Lmax) 32.
x = i, y = j, Lmax = Cnt[i][j];
printf ("%d%d%d\n", X, Y, Lmax); 34.} 35.
return 0; .}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/