洛谷P2038 无线网络发射器选址 水题 枚举
刚开始边界写错了(将128写成127)。
注意n <= 20,所以可以每读入一个点就将其周边更新,这样最多也只会有
40 * 40 * 20 种位置需要被枚举。
Code:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 200;
long long sumv[maxn][maxn];
inline void solve(int downx,int downy,int upx,int upy,int k)
{
for(int i = downy; i <= upy; ++i)
for(int j = downx;j <= upx; ++j)
sumv[i][j] += k;
}
int main()
{
//freopen("in.txt","r",stdin);
int d, n;
cin >> d >> n;
for(int i = 1;i <= n;++i)
{
int y,x,k;
cin >> y >> x >> k;
int downy = max(0, y - d);
int downx = max(0, x - d);
int upy = min(128, y + d);
int upx = min(128, x + d);
solve(downx,downy,upx,upy,k);
}
long long ans = 0;
int cnt = 0;
for(int i = 0;i <= 128;++i)
for(int j = 0;j <= 128;++j)ans = max(ans,sumv[i][j]);
for(int i = 0;i <= 128;++i)
for(int j = 0;j <= 128;++j)if(sumv[i][j] == ans) ++cnt;
cout << cnt << " ";
cout << ans;
return 0;
}