题目传送门

题目大意:给出一幅海洋的描述,0为海平面,负数即有水,在给出的xy坐标的底部安放抽水机,问最多能有多少水。水往低处流,且八个方向都可以。

思路:bfs,记录到每一个节点有效的最低海平面,然后尝试更新周围的点。

但这道题需要优先队列,有效海平面最低的先出队,否则会TLE。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
inline int rd() {
int f = ; int x = ; char s = getchar();
while (s<'' || s>'') { if (s == '-')f = -; s = getchar(); }
while (s >= ''&&s <= '') { x = x * + s - ''; s = getchar(); }x *= f;
return x;
}
const int maxn = ;
ll mp[maxn][maxn],mmp[maxn][maxn],vis[maxn][maxn];
int n, m, x, y;
int fx[][] = { {-,},{,},{,},{,},{,-},{,-},{-,-},{-,} };
struct dian {
int x, y;
ll low;
inline dian(){}
inline dian(int x,int y,ll low):x(x),y(y),low(low){}
inline friend bool operator <(const dian & a, const dian &b) {
return a.low > b.low;
}
};
inline bool check(dian &s)
{
if (s.x <= || s.y <= || s.x > n || s.y > m||vis[s.x][s.y])return false;
if (mp[s.x][s.y] > )return false;
return true;
}
priority_queue<dian >q;
int main() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
scanf("%I64d", &mp[i][j]);
}
}
scanf("%d%d", &x, &y);
if (mp[x][y] > ) {
printf("0\n");
return ;
}
q.push(dian(x, y,mp[x][y]));
ll ans =;
mmp[x][y] = mp[x][y];
vis[x][y] = ;
while (!q. empty()) {
dian st = q.top();
q.pop();
for (int i = ; i < ; i++)
{
dian now = st;
now.x += fx[i][], now.y += fx[i][];
if (!check(now))continue;
now.low= -min(-st.low, -mp[now.x][now.y]);
if (now.low < mmp[now.x][now.y]) {
q.push(now);
mmp[now.x][now.y] = now.low;
vis[now.x][now.y] = ;
}
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
ans -= mmp[i][j];
}
}
printf("%I64d\n", ans); }

Gym - 101572E Emptying the Baltic bfs加剪枝的更多相关文章

  1. hdu6223 Infinite Fraction Path 2017沈阳区域赛G题 bfs加剪枝(好题)

    题目传送门 题目大意:给出n座城市,每个城市都有一个0到9的val,城市的编号是从0到n-1,从i位置出发,只能走到(i*i+1)%n这个位置,从任意起点开始,每走一步都会得到一个数字,走n-1步,会 ...

  2. E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)

    题目链接: E - Emptying the Baltic Kattis - emptyingbaltic 题目大意:n*m的地图, 每个格子有一个海拔高度, 当海拔<0的时候有水. 现在在(x ...

  3. hdu 1044(bfs+dfs+剪枝)

    Collect More Jewels Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  4. HDU 1254 推箱子(BFS加优先队列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. Gym 101617J Treasure Map(bfs暴力)

    http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量 ...

  7. Codeforces Gym 100187E E. Two Labyrinths bfs

    E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/prob ...

  8. HDU 5510 Bazinga 暴力匹配加剪枝

    Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...

  9. UVA - 11882 Biggest Number(dfs+bfs+强剪枝)

    题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的 ...

随机推荐

  1. sed对指定行添加或删除注释

      如下文本   zimu.txt aaaaa #bbbbbb cccccc dddddd 以下命令如果需要在文本中更改 需要加 -i 或者  -ri参数 用sed在aaa前加#注释 sed 's/^ ...

  2. findall 、 search的使用

  3. 批处理基本知识以及进阶 V2.0

    批处理基本知识以及进阶 将以要执行的程序指令 , 像在 dos 模式下一下写入记事本 , 保存成 bat 文件 , 就可以执行了 一 . 简单批处理内部命令简介 1.Echo 命令 打开回显或关闭请求 ...

  4. JavaPersistenceWithHibernate第二版笔记-第七章-002Mapping an identifier bag(@CollectionId、@ElementCollection、@CollectionTable、@Type)

    一.结构 A bag is an unordered collection that allows duplicate elements, like the java.util.Collection ...

  5. getUserMedia API

    getUserMedia API 特别有趣的一个 API,能够调用电脑的摄像头,未来这个 API 将被广泛用来让浏览器和用户之间互动. 如果 <video> 标签和 Canvas 现结合 ...

  6. Shell表达式,如${file##*/}

    Shell表达式,如${file##*/} 2017年10月26日 15:24:40 阅读数:343 今天看一个脚本文件的时候有一些地方不太懂,找了一篇文章看了一些,觉得不错,保留下来. 假设我们定义 ...

  7. HttpServletRequest和ServletRequest的区别.RP

    问题: 请问HttpServletRequest和ServletRequest的区别? 回答: servlet理论上可以处理多种形式的请求响应形式 http只是其中之一 所以HttpServletRe ...

  8. Loading Large Bitmaps Efficiently

    有效地加载大位图文件-Loading Large Bitmaps Efficiently 图像有各种不同的形状和大小.在许多情况下,他们往往比一个典型应用程序的用户界面(UI)所需要的资源更大.例如, ...

  9. C++中的内存重叠问题

    内存重叠,直到做到一个笔试题才知道了什么是内存重叠.先上题目吧,是一个淘宝的笔试题,当时有点懵,不知道这个名词是啥子意思. 题目:补充下面函数代码: 如果两段内存重叠,用memcpy函数可能会导致行为 ...

  10. win7搭建TensorFlow环境

    官网安装指南地址:https://www.tensorflow.org/install/pip 安装过程碰到的问题: 1.创建虚拟环境 virtualenv --system-site-package ...