从外面一点一点往里面拓展(floodfill),每次找出最小的一个点,计算它对答案的贡献就好了。。。

找最小的点的话,直接pq就行

 /**************************************************************
Problem: 1736
User: rausen
Language: C++
Result: Accepted
Time:196 ms
Memory:2116 kb
****************************************************************/ #include <cstdio>
#include <queue> using namespace std;
typedef long long ll;
const int N = ;
const int dx[] = {, , , -};
const int dy[] = {, -, , }; inline int read(); struct data {
int x, y, h;
data(int _x = , int _y = , int _h = ) : x(_x), y(_y), h(_h) {} inline bool operator < (const data &d) const {
return h > d.h;
}
}; int n, m;
int mp[N][N], v[N][N];
priority_queue <data> h; inline ll work(){
ll res = ;
int x, y, k;
data now;
while (!h.empty()) {
now = h.top(), h.pop();
for (k = ; k < ; ++k) {
x = now.x + dx[k], y = now.y + dy[k];
if (x <= || y <= || x > n || y > m || v[x][y]) continue;
v[x][y] = ;
if (mp[x][y] < now.h)
res += now.h - mp[x][y], mp[x][y] = now.h;
h.push(data(x, y, mp[x][y]));
}
}
return res;
} int main() {
int i, j;
m = read(), n = read();
for (i = ; i <= n; ++i)
for (j = ; j <= m; ++j) mp[i][j] = read();
for (i = ; i <= n; ++i)
for (j = ; j <= m; ++j)
if (i == || j == || i == n || j == m)
h.push(data(i, j, mp[i][j])), v[i][j] = ;
printf("%lld\n", work());
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}

BZOJ1736 [Usaco2005 jan]The Wedding Juicer 婚宴的榨汁机的更多相关文章

  1. BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声

    1679: [Usaco2005 Jan]Moo Volume 牛的呼声 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 723  Solved: 346[ ...

  2. BZOJ1677: [Usaco2005 Jan]Sumsets 求和

    1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 570  Solved: 310[Submi ...

  3. BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )

    完全背包.. --------------------------------------------------------------------------------------- #incl ...

  4. BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )

    一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...

  5. BZOJ 1677: [Usaco2005 Jan]Sumsets 求和

    题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 617  Solved: 344[Su ...

  6. 1677: [Usaco2005 Jan]Sumsets 求和

    1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 626  Solved: 348[Submi ...

  7. bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖

    链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...

  8. 【BZOJ1677】[Usaco2005 Jan]Sumsets 求和 递推

    ... #include <iostream> using namespace std; ]; int n,i; int main() { cin>>n; f[]=; ;i&l ...

  9. BZOJ1737 [Usaco2005 jan]Naptime 午睡时间

    断环然后裸DP就好了... $f[i][j][k]$表示1号时间段没有被算入答案,到了第$i$个时间段,一共选了$j$个时间段,$k = 0 /1$表示第i个时间段有没有被算进答案的最优值 $g[i] ...

随机推荐

  1. Fiddler中session的请求/响应类型与图标对照表

  2. STL--list

    List-概述: 列表List是一个线性链表结构(Double—Linked Lists,双链表),它的数据由若干个节点构成,每一个节点都包括一个信息块Info(即实际存储的数据).一个前驱指针Pre ...

  3. 异步上传图片,光用jquery不行,得用jquery.form.js插件

    异步上传图片,光用jquery不行,得用jquery.form.js插件,百度一下下载这个插件,加jquery,引入就可以了 <form id="postbackground" ...

  4. linux安装phpstorm出现 Startup Error: Unable to detect graphics environment

    在centos6.2下在安装phpstorm下遇到 Startup Error: Unable to detect graphics environment 其中jdk安装的版本是 1.7.0_79  ...

  5. ubuntu 卸载/安装 redis

    ubuntu 卸载redis 1. 卸载软件 apt-get remove redis 2. 清除配置 apt-get remove --purge redis 3. 删除残留文件 find / -n ...

  6. 关于我们DOM的知识点

    DOM的概念及子节点类型   前言 DOM的作用是将网页转为一个javascript对象,从而可以使用javascript对网页进行各种操作(比如增删内容).浏览器会根据DOM模型,将HTML文档解析 ...

  7. iOS开发之语音功能实现

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

  8. 【linux命令】:查看系统运行状态,命令top 【转载】

    原文:http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html 简介 top命令是Linux下常用的性能分析工具,能够实时显示系 ...

  9. 【服务器环境搭建-Centos】tmpfs,【转载】

    转载来源:http://www.linuxidc.com/Linux/2013-12/93747.htm tmpfs介绍 tmpfs是一种虚拟内存文件系统,而不是块设备.是基于内存的文件系统,创建时不 ...

  10. java final

    final:(最终的)看不懂时有必要分析内存画图,不同方法的局部变量是相互独立的额不要被所起的名所困扰. 1)每个方法运行时jvm,都会为其开辟一片内存空间.内存空间是属于这个方法的, 同时,方法中的 ...