题目大意:有一个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. editplus 正则删换行

    editplus regular expression  ctrl+h 1.替换开始是空行 ^[\t ]*\n 2.替换换行 \n 3.替换包含某字符 .*@126.* excel去重复(或者保留一个 ...

  2. OSPF的基本配置及DR /BDR选举的实验

    OSPF的基本配置及DR /BDR选举的实验 实验拓扑: 实验目的:掌握OSPF的基本配置 掌握手工指定RID 掌握如何修改OSPF的接口优先级 观察DR BDR选举的过程 实验要求:R3当选为DR ...

  3. java的property

    System.currentTimeMillis() 返回以毫秒为单位的当前时间.System.gc() 垃圾回收System.getProperties().返回当前的系统属性System.getP ...

  4. MOSFET与MOSFET驱动电路原理及应用(转)

    源:http://www.micro-bridge.com/news/news.asp?id=258 在使用MOS管设计开关电源或者马达驱动电路的时候,大部分人都会考虑MOS的导通电阻,最大电压等,最 ...

  5. 阶乘相关<同余与模算术>

    题意: 题目很简明: 令S[n]=1*1!+2*2!+3*3!+4*4!+....+n*n! 求S[n]%10000007 多组测试数据 每组一个n n的范围:1<=n<=1000000 ...

  6. 绑定网关mac,防arp攻击

    netsh i i show innetsh -c i i add neighbors 16 192.168.1.1 08-57-00-51-19-7c

  7. 生成makefile文件编译源文件

    1.利用CodeBlock的cbp文件生成makefile文件 reverse@ubuntu:~/Desktop/CreateMakeFile$ ls cbp2make.linux-x86 freeg ...

  8. PAT (Advanced Level) 1043. Is It a Binary Search Tree (25)

    简单题.构造出二叉搜索树,然后check一下. #include<stdio.h> #include<algorithm> using namespace std; +; st ...

  9. vc6 pbo 文件为空的解决方法

    使用Profile调试vc6应用程序的性能时,将生成pbo文件,今天在vc IDE中增加了命令行启动参数,导致profile无法生成pbo文件,进而无法生成性能报告. 解决方法: 去掉IDE中的命令行 ...

  10. Ubuntu 12.04 中文输入法

    Ubuntu 12.04 中文输入法 [日期:2012-07-28] 来源:Linux社区  作者:lqhbupt [字体:大 中 小]   Ubuntu上的输入法主要有小小输入平台(支持拼音/二笔/ ...