题目大意:有一个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. 解决IIS网站.woff 404 (Not Found)问题

    一.在没有权限操作IIS管理器的情况下,在Web.config中的system.webServer节点进行如下配置: <system.webServer> <staticConten ...

  2. “#ifdef __cplusplus extern "C" { #endif”的定义-----C和C++的互相调用

    "#ifdef __cplusplus extern "C" { #endif"的定义 看一些程序的时候老是有 "#ifdef __cplusplus ...

  3. MapReduce入门例子

    计算文档中不同单词的个数. hello you hello me 步骤如下:

  4. 【转】js/jquery中刷新iframe方法(兼容主流)

    一.js实现刷新两种方式: 1.//方法1 2.document.getElementById('FrameID').contentWindow.location.reload(true); 3.// ...

  5. JSP内置对象--application对象(getRealPath(),getAttributeNames(),getContextPath())

    application对象是javax.servlet.ServletContext接口的实例化对象.是整个servlet的上下文,代表了整个web容器的操作. 常用方法: 1.java.lang.S ...

  6. Codeforces Round #272 (Div. 1) B 构造 math

    http://www.codeforces.com/contest/477/problem/C 题目大意:给你n个集合,每个集合里面有四个数字,他们的gcd是k,输出符合条件的集合中m,m为集合中最大 ...

  7. plsql找外键约束关联的表的方法

    直接Ctrl + 鼠标左键 表名 就可以找到参照表(关联表)的名称 下面的是复杂的方法 这个就是关联的表 这里右键查看 可以查看到参照的表

  8. ZOJ3944People Counting<暴力/枚举>

    题意:输入一张照片,给出人物的特征,判断有多少个人. .O. /|\ (.) 思路:按照3*3的图统计,只要有一个点符合就加1 #include<cstdio> #include<i ...

  9. HDU 1176 免费馅饼(数塔dp)

    一开始被吓到了,后来再仔细一读发现就是一个数塔,没有那么复杂 #include<stdio.h> #include<string.h> #include<algorith ...

  10. CSS3的background-size

    DEMO一.background-size:auto; 我来看第一个DEMO,在前面的DEMO上加上和个class名为"backgroundSizeAuto",在这个Demo上我们 ...