Emptying the Baltic(类似最短路?)
来源:互联网 发布:美萍软件怎么样 编辑:程序博客网 时间:2024/06/16 04:57
题目:https://odzkskevi.qnssl.com/da9adfb686ef541a14cec9856721130a?v=1507986802
E
从排水口(sx,sy)开始,压入优先队列,每次去队头元素,与八个方向上的流量比较,知道队列为空
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<iostream>#include<queue>using namespace std;struct node{int x,y,dep;node(int x,int y,int dep):x(x),y(y),dep(dep){}bool operator<(const node &a)const{return dep>a.dep;}};int n,m;long long sum;int sx,sy;int vis[550][550];int a[550][550];int d[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1};int check(int x,int y){return x>=1&&x<=n&&y>=1&&y<=m&&!vis[x][y]&&a[x][y]<0;}void bfs(){priority_queue<node>q;memset(vis,0,sizeof(vis));q.push(node(sx,sy,a[sx][sy]));sum=-a[sx][sy];vis[sx][sy]=1;while(!q.empty()){node now=q.top();q.pop();for(int i=0;i<8;i++){int x=now.x+d[i][0];int y=now.y+d[i][1];if(check(x,y)){vis[x][y]=1;sum-=max(now.dep,a[x][y]);q.push(node(x,y,max(now.dep,a[x][y])));}}}}int main(){scanf("%d%d",&n,&m);int i,j;for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&a[i][j]);}}scanf("%d%d",&sx,&sy);bfs();printf("%lld\n",sum);return 0;}
阅读全文
0 0
- Emptying the Baltic(类似最短路?)
- 计蒜客 Emptying the Baltic (BFS+Dijkstra)
- Emptying the Baltic
- Gym 101572E Emptying the Baltic(优先队列)
- Gym 101572E Emptying Baltic【优先队列+BFS】
- Codeforces715B-Complete The Graph(最短路)
- 最短路(最短路)
- 【HDU】-find the safest road(最短路)(dijkstra)
- Til the Cows Come Home(最短路)
- A Walk Through the Forest(最短路+dfs)
- hdu Choose the best route(最短路 --- Dijkstra)
- UVA 10537 The Toll! Revisited(最短路变形)
- A Walk Through the Forest(hdu1142,最短路+dfs)
- hdu2680 Choose the best route 最短路(Dijkstra算法)
- hdu1596 find the safest road(最短路)
- UVA 10917 Walk Through the Forest(最短路+dp)
- HDU 1596find the safest road(最短路变形)
- HDU 2680Choose the best route(dijk最短路)
- mysql提示access denied for user ''@'localhost' to database
- java之poi
- Codeforces 873D:构造题
- FLAG_ACTIVITY_CLEAR_TOP会重启Activity的问题解决
- ConfigReader(三十一)—— ReadIGuideTaskConfig
- Emptying the Baltic(类似最短路?)
- 单链表的基本操作
- 爬取一个本地网页
- [分治][线性基]BZOJ 4184: shallot
- linux命令:ps命令
- 一人逾期,痛苦全家人!
- Android studio中常用快捷键
- 南阳理工_65另一种阶乘问题
- Java关键字static、final使用小结