您的位置:首页 > 理论基础 > 计算机网络

[luoguP2038] 无线网络发射器选址(模拟)

2017-05-22 14:44 218 查看

传送门

 

又是个模拟水题,考虑边界就好,连long long都不用开。

 

——代码

#include <cstdio>
#include <iostream>

int n, d, ans, max;
int a[201][201];

inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
}

int main()
{
int i, j, x, y, sum;
d = read();
n = read();
for(i = 1; i <= n; i++)
{
x = read();
y = read();
a[x][y] = read();
}
for(i = 0; i <= 128; i++)
for(j = 0; j <= 128; j++)
{
sum = 0;
for(x = i - d; x <= i + d; x++)
for(y = j - d; y <= j + d; y++)
if(x >= 0 && x <= 128 && y >= 0 && y <= 128)
sum += a[x][y];
if(sum > max)
{
max = sum;
ans = 1;
}
else if(sum == max) ans++;
}
printf("%d %d\n", ans, max);
return 0;
}
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: