题目传送门

题目大意:给出一幅海洋的描述,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. Spring注解-TaskScheduler

    一.定义配置类 import org.springframework.context.annotation.ComponentScan; import org.springframework.cont ...

  2. 探究QA职能

    测试人员一般是被外界普遍认为是QC,即对产品的质量进行检测,找出质量问题并配合相关人员解决问题,从而管控产品质量,说通俗点就是帮开发找漏洞,给开发擦屁股:如果线上出现bug,就是你没有测试完整,最累的 ...

  3. 图片缓存核心类LruCache

    该类类似一个缓存池,具体可参考 http://www.fengfly.com/plus/view-214546-2.html

  4. Maven学习笔记2-maven命令

    help:active-profiles列出当前构建中活动的Profile(项目的,用户的,全局的). help:effective-pom显示当前构建的实际POM,包含活动的Profile. hel ...

  5. Codeforces 1108F (MST Unification) (树上倍增 or 改进 kruksal)

    题意:给你一张n个节点和m条边的无向连通图, 你可以执行很多次操作,对某一条边的权值+1(对于每条边,可以不加,可以无限次加),问至少进行多少次操作,可以使这张图的最小生成树变得唯一,并且最小生成树的 ...

  6. HDU 5038 Grade (水题,坑题)

    题意:给 n 个数,输出众数,但是如果所有的频率都相同但数不同输出 Bad Mushroom. 析:直接记录个数直接暴力就,就是要注意只有一种频率的时候. 代码如下: #pragma comment( ...

  7. TinkerPop中的遍历:图的遍历中谓词、栅栏、范围和Lambda的说明

    关于谓词的注意事项 P是Function<Object,Boolean>形式的谓词.也就是说,给定一些对象,返回true或false.所提供的谓词在下表中概述,并用于各种步骤,例如has( ...

  8. Server.MapPath方法的应用方法

    老是忘记Server.MapPath的使用方法了,下面记录一下,以备后用:总注:Server.MapPath获得的路径都是服务器上的物理路径,也就是常说的绝对路径1.Server.MapPath(&q ...

  9. 对Dapper的一点改造

    微软推出的ORM, EF在我开发的项目中给我的感觉一直都是慢.优点是高度封装的底层.便于开发. Dapper在多篇性能比较的网站中.都是名列前三.缺点是手写SQL,不便于开发.   如果能结合EF的优 ...

  10. BIO与NIO的方式实现文件拷贝

    面试题 - 编程实现文件拷贝.(这个题目在笔试的时候经常出现,下面的代码给出了两种实现方案) import java.io.FileInputStream; import java.io.FileOu ...