BZOJ1736 [Usaco2005 jan]The Wedding Juicer 婚宴的榨汁机
从外面一点一点往里面拓展(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 婚宴的榨汁机的更多相关文章
- BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声
1679: [Usaco2005 Jan]Moo Volume 牛的呼声 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 723 Solved: 346[ ...
- BZOJ1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 570 Solved: 310[Submi ...
- BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )
完全背包.. --------------------------------------------------------------------------------------- #incl ...
- BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )
一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...
- BZOJ 1677: [Usaco2005 Jan]Sumsets 求和
题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 617 Solved: 344[Su ...
- 1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 626 Solved: 348[Submi ...
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
- 【BZOJ1677】[Usaco2005 Jan]Sumsets 求和 递推
... #include <iostream> using namespace std; ]; int n,i; int main() { cin>>n; f[]=; ;i&l ...
- BZOJ1737 [Usaco2005 jan]Naptime 午睡时间
断环然后裸DP就好了... $f[i][j][k]$表示1号时间段没有被算入答案,到了第$i$个时间段,一共选了$j$个时间段,$k = 0 /1$表示第i个时间段有没有被算进答案的最优值 $g[i] ...
随机推荐
- php工具 phpstorm 的快捷键 的使用(待添加
参考网址:http://www.cnblogs.com/jikey/p/3491798.html 1. ctrl+tab 键,可以切换各个选项卡 页面 2. shift+enter 键,无论光标在本行 ...
- LTE Module User Documentation(翻译6)——物理误差模型、MIMO模型、天线模型
LTE用户文档 (如有不当的地方,欢迎指正!) 9 PHY Error Model 物理误差模型包含数据误差模型和下行控制误差模型,两者默认为激活.可以使用 ns-3 属性系统去激活,具体为: ...
- Doragon Kuesuto 1.0
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { ; ; ; int actio ...
- .net 连接sqlserver类库
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...
- Single Number III
Description: Given an array of numbers nums, in which exactly two elements appear only once and all ...
- 修改jsp文件tomcat发布失败(Could not delete May be locked by another process)
突然项目修改jsp文件后,tomcat不能发布, Publishing failed with multiple errors Could not delete D:/Tomcat 6.0/web ...
- C#_微信支付V3
基础问题先排除: 确保 商户功能 审核通过,会有官方邮件 支付授权目录(注意看文档,大小写关系很大 点击支付按钮,提示“access_denied” 网上有很多关于此问题的解决) 点击支付按钮,提示“ ...
- 【论文阅读记录】Real-Time Correlative Scan Matching
这篇文章是谷歌的Cartograph中实现real_time_correlative_scan_matcher的论文 Real-Time Correlative Scan MatchingEdwin ...
- commonJS — 字符串操作(for String)
for String github: https://github.com/laixiangran/commonJS/blob/master/src/forString.js 代码 /** * Cre ...
- drupal里面的ajax最粗浅的理解-流程
1, form里面的ajax所在地表单元素有一个事件,激发system/ajax,相应的有ajax_form_callback(), 会把被改变的元素值传到form_state[values]中, ...