bzoj1619 / P2919 [USACO08NOV]守护农场Guarding the Farm
2024-10-20 07:37:14
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 ;
}
最新文章
- .Net Core[译文]
- OkHttp 3.4入门
- javascript 事件委托,jq,js模拟事件
- 如何用ssh挂载远程目录
- User_Agent_List 浏览器信息列表
- River Hopscotch(二分)
- [13] static 和 final
- Python 函数式编程和面向对象编程
- 使用强类型实体Id来避免原始类型困扰(一)
- 积极参与开源项目,促进.NET Core生态社区发展
- maven配置阿里镜像仓库
- Django(十二)—关于查询知识点总结
- Java集合排序方法comparable和comparator的总结
- 关于cordova 状态栏设置
- MySQL 安装方法
- Django中使用Celery实现定时任务(用djcelery)
- JSON学习资料整理
- 汇编_指令_SHL、SHR、SAL、SAR、ROL、ROR、RCL、RCR
- 新的方法(Set<;T>;)实现mvc的crud
- Android Bug BaseExpandableListAdapter, getChildView
热门文章
- IOS中数组的使用(NSArray, NSSet, NSDictionary)
- 【PHP+Redis】 php-redis 操作类 封装
- activemq 实战 一
- 窗口大小改变绑定resize事件
- rpm方式安装 gitlab centos7
- mysql 之 group by 性能优化 查询与统计分离
- 日志系统实战 AOP静态注入
- 【BZOJ1453】[Wc]Dface双面棋盘 线段树+并查集
- c# 执行 CreateHandle() 时无法调用值 Dispose()
- mysql存储过程基础示例