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 ;
}

最新文章

  1. .Net Core[译文]
  2. OkHttp 3.4入门
  3. javascript 事件委托,jq,js模拟事件
  4. 如何用ssh挂载远程目录
  5. User_Agent_List 浏览器信息列表
  6. River Hopscotch(二分)
  7. [13] static 和 final
  8. Python 函数式编程和面向对象编程
  9. 使用强类型实体Id来避免原始类型困扰(一)
  10. 积极参与开源项目,促进.NET Core生态社区发展
  11. maven配置阿里镜像仓库
  12. Django(十二)—关于查询知识点总结
  13. Java集合排序方法comparable和comparator的总结
  14. 关于cordova 状态栏设置
  15. MySQL 安装方法
  16. Django中使用Celery实现定时任务(用djcelery)
  17. JSON学习资料整理
  18. 汇编_指令_SHL、SHR、SAL、SAR、ROL、ROR、RCL、RCR
  19. 新的方法(Set&lt;T&gt;)实现mvc的crud
  20. Android Bug BaseExpandableListAdapter, getChildView

热门文章

  1. IOS中数组的使用(NSArray, NSSet, NSDictionary)
  2. 【PHP+Redis】 php-redis 操作类 封装
  3. activemq 实战 一
  4. 窗口大小改变绑定resize事件
  5. rpm方式安装 gitlab centos7
  6. mysql 之 group by 性能优化 查询与统计分离
  7. 日志系统实战 AOP静态注入
  8. 【BZOJ1453】[Wc]Dface双面棋盘 线段树+并查集
  9. c# 执行 CreateHandle() 时无法调用值 Dispose()
  10. mysql存储过程基础示例