题意:



思路:

搞一个priority_queue 先把边界加进去 不断取最小的 向中间扩散

//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
#define int long long
struct Node{int h,x,y;Node(int a,int b,int c){h=a,x=b,y=c;}};
priority_queue<Node>pq;
bool operator <(Node a,Node b){return a.h>b.h;}
int n,m,ans,a[305][305],xx[]={1,-1,0,0},yy[]={0,0,1,-1};
bool vis[305][305];
signed main(){
memset(vis,1,sizeof(vis));
scanf("%lld%lld",&m,&n);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%lld",&a[i][j]),vis[i][j]=0;
for(int i=1;i<=n;i++)pq.push(Node(a[i][1],i,1)),pq.push(Node(a[i][m],i,m)),vis[i][m]=vis[i][1]=1;
for(int i=2;i<=m;i++)pq.push(Node(a[1][i],1,i)),pq.push(Node(a[n][i],n,i)),vis[n][i]=vis[1][i]=1;
while(!pq.empty()){
Node t=pq.top();pq.pop();
for(int i=0;i<4;i++){
int dx=t.x+xx[i],dy=t.y+yy[i];
if(!vis[dx][dy]){
if(a[dx][dy]<t.h)ans+=t.h-a[dx][dy],pq.push(Node(t.h,dx,dy));
else pq.push(Node(a[dx][dy],dx,dy));
vis[dx][dy]=1;
}
}
}
printf("%lld\n",ans);
}

POJ 2227 FloodFill (priority_queue)的更多相关文章

  1. POJ 2227 The Wedding Juicer (优先级队列+bfs+dfs)

    思路描述来自:http://hi.baidu.com/perfectcai_/item/701f2efa460cedcb0dd1c820也可以参考黑书P89的积水. 题意:Farmer John有一个 ...

  2. POJ 3268 Dijkstra+priority_queue或SPFA

    思路:正向建边,一遍Dijkstra,反向建边,再一遍Dijkstra.ans加在一起输出最大值. (SPFA也行--) // by SiriusRen #include <queue> ...

  3. POJ 2437 贪心+priority_queue

    题意: 思路: 贪心 能不覆盖的就不盖 写得很乱 左闭右开的 temp //By SiriusRen #include <queue> #include <cstdio> #i ...

  4. POJ 2431 Expedition (priority_queue或者multiset可解)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18655   Accepted: 5405 Descr ...

  5. STL(pair map set vector priority_queue) poj 3297

    POJ 3297 算法竞赛初级杂烩包 题意:学生选课,没个学生只能选一门课.大写字符是课的名字,小写是人名.如果课程后面有多个相同名字算一个,如果一个人选多门课,则他选不上课,输出课和每门课选课人数 ...

  6. 优先队列(priority_queue)的cmp,POJ(2051)

    sort()函数的cmp为函数,priority_queue的cmp为类,具体写法是: struct Node { int i,j; } node[]; struct cmp { bool opera ...

  7. poj 3253 Fence Repair(priority_queue)

    Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 40465   Accepted: 13229 De ...

  8. POJ 3190 priority_queue 贪心

    思路: 贪心?就算是吧 先把所有的开始时间排个序 如果当前的能匹配上已有的牛栏,就找开始时间最早的那个. 否则新加一个牛栏 整个过程用priority_queue实现就OK了.. //By Siriu ...

  9. HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题

    Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...

随机推荐

  1. C语言基础-第三章

    C语句和数据输入/输出(函数) 1.printf();输出函数 2.getch();输入函数 3.scanf();格式输入 4.puts();字符串输出 5.gets();字符串输入

  2. OpenGL编程逐步深入(六)平移变换

    准备知识 从这一节我们开始接触3D对象各种各样的变换,使其显示在屏幕上看起来有深度的感觉.通常每一种变换都是通过矩阵来实现的,把这些变换矩阵逐个的乘起来,然后用乘积乘以顶点位置.在每个教程中,我们致力 ...

  3. @synchronized 再考察

    核心是:将标示对象与锁建立关联. 线程 锁 标识: 异常: NSString *test = @"test"; @try {     // Allocates a lock for ...

  4. UI Framework-1: Aura Focus and Activation

    Focus and Activation Focus and Activation are closely related.   Definitions Focused window - this i ...

  5. Embedding Flash Fullscreen in the Browser Window

    For Developers‎ > ‎Design Documents‎ > ‎ Embedding Flash Fullscreen in the Browser Window Auth ...

  6. docker切换默认镜像源

    docker切换默认镜像源   基于 debian8 默认安装的 docker 镜像源是在国外,pull 镜像的时候奇慢无比,需要自己手动切换成国内的镜像源. 1. 修改配置文件 docker 默认的 ...

  7. win下通过pip安装TensorFlow

    官方介绍(超详细):https://www.tensorflow.org/install/pip 按照官方介绍,不同的TensorFlow版本只支持特定的python版本所以你要是下载.whl包安装的 ...

  8. unity 5.6.1 Oculus手柄输入问题

    unity文档中提到 轴的 ID 是5和6,但是测试后发现,ID是6和7,很坑 void Update () { if (Input.GetKeyDown(KeyCode.JoystickButton ...

  9. 【SRM 717 div2 A】 NiceTable

    Problem Statement You are given a vector t that describes a rectangular table of zeroes and ones. Ea ...

  10. CSU 1506 Double Shortest Paths

    1506: Double Shortest Paths Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 49  Solved: 5 Description ...