NOIP2014 Day2 T1(暴力枚举)

数据范围很小,直接每个路口枚举放置点,再暴力统计覆盖的公共场所就可以了
注意边界的判定,这里用的判定比较短,具体可以看代码的相关部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
const int MAXN = 129 + 5;
int d, n, ma[MAXN][MAXN];
void clean() {
ms(ma, 0);
}
void init() {
clean();
for (int i=1;i<=n;i++) {
int x, y, k;
scanf("%d%d%d", &x, &y, &k);
ma[x][y] = k;
}
}
void solve() {
int bs = 0, fa = 0;
for (int x=0;x<=128;x++) {
for (int y=0;y<=128;y++) {
int tot = 0;
for (int i=x-d;i<=x+d;i++) {
for (int j=y-d;j<=y+d;j++) {
if (i>=0&&j>=0&&i<=128&&j<=128) tot += ma[i][j];
}
}
if (tot>bs) {
bs = tot, fa = 1;
} else if (tot==bs) fa++;
}
}
printf("%d %d\n", fa, bs);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);freopen("1.out", "w", stdout);
#endif
while (scanf("%d%d", &d, &n)==2) init(), solve();
return 0;
}

------ 本文结束 ------