Gym - 101572E Emptying the Baltic bfs加剪枝
题目大意:给出一幅海洋的描述,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加剪枝的更多相关文章
- hdu6223 Infinite Fraction Path 2017沈阳区域赛G题 bfs加剪枝(好题)
题目传送门 题目大意:给出n座城市,每个城市都有一个0到9的val,城市的编号是从0到n-1,从i位置出发,只能走到(i*i+1)%n这个位置,从任意起点开始,每走一步都会得到一个数字,走n-1步,会 ...
- E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)
题目链接: E - Emptying the Baltic Kattis - emptyingbaltic 题目大意:n*m的地图, 每个格子有一个海拔高度, 当海拔<0的时候有水. 现在在(x ...
- hdu 1044(bfs+dfs+剪枝)
Collect More Jewels Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1254 推箱子(BFS加优先队列)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1254 推箱子 Time Limit: 2000/1000 MS (Java/Others) Me ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- Gym 101617J Treasure Map(bfs暴力)
http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量 ...
- Codeforces Gym 100187E E. Two Labyrinths bfs
E. Two Labyrinths Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/prob ...
- HDU 5510 Bazinga 暴力匹配加剪枝
Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...
- UVA - 11882 Biggest Number(dfs+bfs+强剪枝)
题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的 ...
随机推荐
- Mysql如何将一张表重复数据删除
MySQL无法select 和 delete,update同时进行 只有将group By 出来不重复的数据进行insert到一张和之前同样类型的新表里面 转换思路,解决问题!
- 【266】增加bash文件的执行权限
正常需要通过[bash pass.sh]来执行文件,但是可以通过增加bash文件的执行权限实现通过[./pass.sh]或者[pass.sh]来执行文件. 方法:通过chmod来增加权限,下面四种方法 ...
- liunx环境,摄像头无法识别,解决方案
今天无语了,linux14.04系统下,使用罗技c270摄像头.发现插上没有反应,系统版本: lenovo-myc@lenovomyc-Lenovo-Product:~/Downloads$ unam ...
- re.findall 两个连续匹配成功的输出后一个
- jQuery-图片的放大镜显示效果(需要大小图)
1.default.aspx <%@ Page Language=.2em; height:.1em; text-align:center; font-size:128px;} .zxx_ ...
- CustomProgressDialog
1 ,布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr ...
- Excel VBA连接MySql 数据库获取数据
编写Excel VBA工具,连接并操作Mysql 数据库. 系统环境: OS:Win7 64位 英文版 Office 2010 32位 英文版 1.VBA连接MySql前的准备 Tools---> ...
- ISIS协议
ISIS协议是中间系统到中间系统协议(Intermediate system to intermediate system),是一种内部网管协议,是电信运营商普遍采用的内部网管协议之一. 简单的说IS ...
- Umbraco中获取UmbracoContext
在Umbraco项目中,获取当前的UmbracoContext几乎是都需要用到的,我们一般通过一个静态方法来获取,代码如下 public class ContextHelpers { public s ...
- python--tkinter桌面编程开发--记事本
什么是TK\Tkinter Tkinter是连接Python和TK图形库的一个纽带(接口) Hello Tkinter from tkinter import * root=Tk() #tk类的一个实 ...