P2919 [USACO08NOV]守护农场Guarding the Farm

相似题:P3456 [POI2007]GRZ-Ridges and Valleys

按海拔是否相同分块

每次bfs海拔相同的块,根据与周围的块的大小关系判断是否是山丘。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cctype>
#define re register
using namespace std;
void read(int &x){
char c=getchar();x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=(x<<)+(x<<)+(c^),c=getchar();
}
#define N 702
const int d1[]={,,,-,,,-,-};
const int d2[]={,,-,,,-,,-};
struct data{int x,y;};
int n,m,H[N][N],ans; bool vis[N][N];
void bfs(int f1,int f2){
queue <data> h; h.push((data){f1,f2});
vis[f1][f2]=; int p=;
while(!h.empty()){
data u=h.front(); h.pop();
for(int i=;i<;++i){
int r1=u.x+d1[i],r2=u.y+d2[i];
if(r1<||r1>n||r2<||r2>m) continue;
p&=(H[r1][r2]<=H[u.x][u.y]);//是否是山丘
if(vis[r1][r2]) continue;
if(H[r1][r2]==H[u.x][u.y])
h.push((data){r1,r2}),vis[r1][r2]=;
}
}ans+=p;
}
int main(){
read(n);read(m);
for(re int i=;i<=n;++i)
for(re int j=;j<=m;++j)
read(H[i][j]);
for(re int i=;i<=n;++i)
for(re int j=;j<=m;++j)
if(!vis[i][j]) bfs(i,j);
printf("%d",ans);
return ;
}

bzoj1619 / P2919 [USACO08NOV]守护农场Guarding the Farm的更多相关文章

  1. 洛谷——P2919 [USACO08NOV]守护农场Guarding the Farm

    P2919 [USACO08NOV]守护农场Guarding the Farm 题目描述 The farm has many hills upon which Farmer John would li ...

  2. 洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm

    题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety ...

  3. 洛谷—— P2919 [USACO08NOV]守护农场Guarding the Farm

    https://www.luogu.org/problem/show?pid=2919 题目描述 The farm has many hills upon which Farmer John woul ...

  4. 【luogu P2919 [USACO08NOV]守护农场Guarding the Farm】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2919 1.搜索的时候分清楚全局变量和局部变量的区别 2.排序优化搜索 #include <cstdio ...

  5. P2919 [USACO08NOV]守护农场Guarding the Farm

    链接:P2919 ----------------------------------- 一道非常暴力的搜索题 ----------------------------------- 注意的是,我们要 ...

  6. BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 491  S ...

  7. 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 498  Solve ...

  8. 洛谷 P3079 [USACO13MAR]农场的画Farm Painting

    P3079 [USACO13MAR]农场的画Farm Painting 题目描述 After several harsh winters, Farmer John has decided it is ...

  9. bzoj1619[Usaco2008 Nov]Guarding the Farm 保卫牧场

    Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...

随机推荐

  1. 《转》python学习(3)

    转自http://www.cnblogs.com/BeginMan/archive/2013/06/03/3114974.html 1.print语句调用str()函数显示,交互式解释器调用repr( ...

  2. MUI 页面跳转(传值+接收)

    官方:做web app,一个无法避开的问题就是转场动画:web是基于链接构建的,从一个页面点击链接跳转到另一个页面, 如果通过有刷新的打开方式,用户要面对一个空白的页面等待: 如果通过无刷新的方式,用 ...

  3. java基础---->多个排序的拓展

    根据一些特定的规则,我们可以利用java的反射机制做到很有趣的封装. java的排序封装 一.定义一些comparator AmountComparatorAsc:amount升序 package c ...

  4. java基础---->java调用oracle存储过程

    存储过程是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中,经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它.今天 ...

  5. java基础---->Base64算法的使用

    Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,可用于在HTTP环境下传递较长的标识信息.详细的Base64信息,可以参见维基百科:https://en.wikipedia.org ...

  6. 关于js的面向对象设计

    function Person( name, age ){ this.name = name; this.age = age; this.sleep = function(){ alert( this ...

  7. Servlet 工程 web.xml 中的 servlet 和 servlet-mapping 标签 《转载》

    摘录某个工程的 web.xml 文件片段: 访问顺序为1—>2—>3—>4,其中2和3的值必须相同. url-pattern 标签中的值是要在浏览器地址栏中输入的 url,可以自己命 ...

  8. [Fine Uploader] 用Fine Uploader+ASP.NET MVC实现ajax文件上传[代码示例]

    Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件的 Javascript 组件   This project attempts to ach ...

  9. onethink重新安装后,还原数据库后,登陆不了解决办法!

    在用onethink开发的时候,为了防止修改出错,我会在开发下一个功能的对上一个功能代码整体进行备份,如果出错就返回上一个版本再次修改. 但是会发现一个问题,如果如果返回到上一个版本,重新安装完成之后 ...

  10. Java导出Excel表,POI 实现合并单元格以及列自适应宽度(转载)

    POI是apache提供的一个读写Excel文档的开源组件,在操作excel时常要合并单元格,合并单元格的方法是: sheet.addMergedRegion(new CellRangeAddress ...