UVa 10360 - Rat Attack
题目大意:有一个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的更多相关文章
- 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 ...
- 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...
- uva 11195 Another queen (用状态压缩解决N后问题)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- Backtracking algorithm: rat in maze
Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- C++:string类的使用
类 <string> std::string String类的定义 , 其也是个模板类 typedef basic_string<char> string; String cl ...
- Chapter 1 First Sight——9
One of the best things about Charlie is he doesn't hover. 一件最好的事是查理兹他不在附近. He left me alone to unpac ...
- Linux 查询程序安装路径 是否安装
rpm -ql httpd #[搜索rpm包]--list所有文件安装目录 rpm -q mysql //查询程序是否安装 关于rpm详细用法 参考 http://www.cnblogs.com/x ...
- 关于MyEclipse不停报错multiple problems have occurred 或者是内存不足 的解决办法
这是因为 worksapace与svn代码不一样,要更新! 一更新就好了,困扰死我了,卧槽,搞了2个小时,难怪svn一提交就卡死人,原来还就是svn的问题,更新一下就行.
- 转: window中使用PSFTP/WinSCP实现SFTP上传下载
sftp 服务器: dbmonitor 1.sftp属于交互式的,所以你得缓存下命令#!/bin/shsftp -o Port=3322 root@172.16.1.21:/opt << ...
- VIEWCONTROLLER的启动流程
转载自:http://sunnyyoung.net/post/ios/2015-04-22-viewcontrollerde-qi-dong-liu-cheng-yu-jie-xi VIEWCONTR ...
- hrbustoj 2013 Play Game 2(博弈)
注释在代码里 /* 1.若输入2 ~ 9 ,因为Stan 是先手,所以Stan 必胜 2.若输入10~18 ,因为Ollie 是后手,不管第一次Stan 乘的是什么,Stan肯定在 2 ~ 9 之间, ...
- windows编程:创建DLL
创建DLL Dll是动态链接库的缩写,可以作为附加代码动态映射到进程的地址空间中. 动态库的一般创建方法如下 方法1.使用 __declspec(dllexport) 方式导出 一般的框架如下 // ...
- JavaFX 2.0+ WebView /WebEngine render web page to an image
http://stackoverflow.com/questions/7796558/javafx-2-0-webview-webengine-render-web-page-to-an-image ...
- Eclipse开发工具的使用之-使用Eclipse的Debug调试Android程序
1.设置断点,双击Eclipse编辑界面的边界,或者右击编辑界面的边界,快捷键Ctrl+Shift+B. 2.F11键开始调试程序,程序安装到手机之后,并不会自动运行,需要你手动运行到断点处. 3.运 ...