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.剪枝方案:在当前的处境下,找出所有还能到达的 ...
随机推荐
- eclipse自动生成带参数说明方法注释
自动生成方法的注释格式,例如 /*** @param str* @return * @throws ParseException*/ 快捷键是alt+shift+j,将光标放在方法名上,按快捷键.会 ...
- JavaScript的流程控制语句
JS的核心ECMAScript规定的流程控制语句和其他的程序设计语言还是蛮相似的.我们选择一些实用的例子来看一下这些语句.顺序结构我们在这里就不再提到,直接说条件和循环以及其他语句.一.条件选择结构 ...
- Mac系统下MySql下载MySQL5.7及详细安装流程
一.在浏览器当中输入以下地址 https://dev.mysql.com/downloads/mysql/ 二.进入以下界面:直接点击下面位置 ,选择跳过登录 点过这后直接下载. 三.下载完成后 ...
- AndroidImageSlider(图片轮播控件)
1,引入 dependencies { compile "com.android.support:support-v4:+" compile 'com.squareup.picas ...
- 【总结整理】js获取css的属性(内部,外部,内嵌(写在tag中))
在JS中需要获取某个元素的宽高或者是绝对定位的位置信息,通常我们会这么写: var elemWidth = elem.style.width; console.log(elemWidth); //(空 ...
- 使用HttpClient进行Post通信
---------------siwuxie095 首先到 Apache官网 下载相关的库文件 Apache官网:http://www.apac ...
- winform 公共控件 ListView
//数据显示,刷新 public void F5() { listView1.Items.Clear(); List<Students> Stu = new StudentsData(). ...
- for与break的用法
# Auther: Aaron Fan age_of_oldboy = 56 #执行3次循环for i in range(3): guess_age = int(input("猜一下oldb ...
- 树莓派研究笔记(5)-- FM网络收音机
1. 安装mpc sudo apt-get install mpd mpc 2.添加流.注意,这里有个坑,如果下面这个地址不能用,那么就无法测试了.建议先下载一个龙卷风或者酷狗网络收音机,然后添加地址 ...
- ArcGIS Server GP服务使用常见错误总结
ArcGIS GP服务问题列表 输入参数错误 在使用GP服务时,从创建模型到发布服务,再到调用服务,整个过程都需要注意输入参数和输出参数的问题.GP服务支持的输入和输出参数可详见 http://hel ...