题目大意:有一个1025*1025的矩阵,每个矩阵元素保存这个点上老鼠的数量。现有一种气体炸弹,能覆盖“半径”为d的矩形,在这个范围内可以消灭所有的老鼠,让你找出合适的放置炸弹的位置使的消灭的老鼠数量最多。

  如果暴力枚举的话会超时,考虑到题中有老鼠的点不超过20000个,可以用m[i][j]保存将炸弹放到第i行第j列时消灭老鼠的数量(初始化为0),当某个点有老鼠时更新“半径”为d范围内的m值(加上该点的老鼠数量),这样可以减小时间复杂度。

 #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 1030 int m[MAXN][MAXN]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
scanf("%d", &T);
while (T--)
{
int d;
scanf("%d", &d);
int n;
scanf("%d", &n);
memset(m, , sizeof(m));
for (int i = ; i < n; i++)
{
int x, y, num;
scanf("%d%d%d", &x, &y, &num);
int x_min = max(, x-d);
int x_max = min(, x+d);
int y_min = max(, y-d);
int y_max = min(, y+d);
for (int p = x_min; p <= x_max; p++)
for (int q = y_min; q <= y_max; q++)
m[p][q] += num;
}
int lmax = , x = , y = ;
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
if (m[i][j] > lmax)
{
x = i;
y = j;
lmax = m[i][j];
}
printf("%d %d %d\n", x, y, lmax);
}
return ;
}

UVa 10360 - Rat Attack的更多相关文章

  1. UVA - 11134 Fabled Rooks[贪心 问题分解]

    UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to t ...

  2. 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...

  3. uva 11195 Another queen (用状态压缩解决N后问题)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  5. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  6. Backtracking algorithm: rat in maze

    Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...

  7. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  8. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  9. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

随机推荐

  1. (转)Windows管道(Pipe)重定向stdout,stderr,stdin

    参考: http://qiusuoge.com/11496.html http://www.cnblogs.com/BoyXiao/archive/2011/01/01/1923828.html st ...

  2. Android Studio的使用(十三)--设置方法分割线

    1.只需要在设置中选中show method separators 即可.

  3. scp命令报错-bash: scp: command not found

    # scp -bash: scp: command not found # which scp /usr/bin/scp # rpm -qf /usr/bin/scp openssh-clients- ...

  4. Abandoned country

    Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. pop动画使用示例

    // 弹簧动画 POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame]; an ...

  6. (转)MultipleOutputFormat和MultipleOutputs

    MultipleOutputFormat和MultipleOutputs http://www.cnblogs.com/liangzh/archive/2012/05/22/2512264.html ...

  7. c# winform 点击按钮切换tabcontrol标签

    this.tabControl1.TabPages.Remove(tabPage1); this.tabControl1.TabPages.Remove(tabPage2); this.tabCont ...

  8. Super Jumping! Jumping! Jumping! 基础DP

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. Entity Framework Power Tools Beta 3

    http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/ PM> Install-P ...

  10. Apache Commons工具集简介(转)

    此文为转帖,原帖地址:http://zhoualine.iteye.com/blog/1770014