bzoj1619 / P2919 [USACO08NOV]守护农场Guarding the Farm
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的更多相关文章
- 洛谷——P2919 [USACO08NOV]守护农场Guarding the Farm
P2919 [USACO08NOV]守护农场Guarding the Farm 题目描述 The farm has many hills upon which Farmer John would li ...
- 洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm
题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety ...
- 洛谷—— P2919 [USACO08NOV]守护农场Guarding the Farm
https://www.luogu.org/problem/show?pid=2919 题目描述 The farm has many hills upon which Farmer John woul ...
- 【luogu P2919 [USACO08NOV]守护农场Guarding the Farm】 题解
题目链接:https://www.luogu.org/problemnew/show/P2919 1.搜索的时候分清楚全局变量和局部变量的区别 2.排序优化搜索 #include <cstdio ...
- P2919 [USACO08NOV]守护农场Guarding the Farm
链接:P2919 ----------------------------------- 一道非常暴力的搜索题 ----------------------------------- 注意的是,我们要 ...
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 498 Solve ...
- 洛谷 P3079 [USACO13MAR]农场的画Farm Painting
P3079 [USACO13MAR]农场的画Farm Painting 题目描述 After several harsh winters, Farmer John has decided it is ...
- bzoj1619[Usaco2008 Nov]Guarding the Farm 保卫牧场
Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...
随机推荐
- 一加氢OS发布会 观看小结
观看地址:http://v.youku.com/v_show/id_XMTI0ODkzNTg5Mg==.html?from=s1.8-1-1.2八种基本色调.33%自由:top33%位置放壁纸,底部桌 ...
- 【Mysql】解决插入数据出现 Incorrect string value: '\xF0\x9F\x92\x8BTi...'错误
背景: 用户输入的表单里边.存在 手机自带的表情, 在执行插入时候报错 Incorrect string value: '\xF0\x9F\x92\x8BTi...' 错误原因:我们在设置mysql ...
- [WIFI] WIFI 破解(初级)
话不多说,先来看看字典破解 wpa2 的效果 =================================== ========================================= ...
- 批量远程执行linux服务器程序--基于pxpect(多进程、记日志版)
#!/usr/bin/python '''Created on 2015-06-09@author: Administrator''' import pexpect import os,sys fro ...
- spring全局变量引起的并发问题
先看下面小段代码,一个controller,一个service. controller.java代码: ........ @Autowired private XXXService ...
- MacBook鼠标指针乱窜/不受控制问题的解决方法
用了快一年的MacBook Pro最近出现了奇怪的问题.出问题时,鼠标不受控制,屏幕上鼠标指针乱窜,还时不时自动点击,犹如电脑被人远程控制一般.不管是用trackpad还是用外接鼠标,都是同样问题.电 ...
- Oracle HA 之 SERVICE和DRM实战
第一部分:service实战 --oracle 11gR2中创建service的方法:db console和srvctl两种方法. --db console创建service方法-略 --srvctl ...
- Eclipse For Android 代码自动提示功能
Eclipse for android 实现代码自动提示智能提示功能,介绍 Eclipse for android 编辑器中实现两种主要文件 java 与 xml 代码自动提示功能,解决 eclips ...
- 前端程序员:月薪 5K 到 5 万
入行行头:5 大硬件 请准备好以下东西 一颗人类的大脑:智商在平均水平线以上即可 一份强烈的渴望:我的代码要可以运行在任何一个有浏览器的设备上. 一台笔记本电脑:不需要花费很多钱得那种,只要它可以运行 ...
- Apache 2.4 编码GB2312中文乱码的问题
今天部署了一个项目,代码和数据库都是gb2312的,本地和服务器都是apache2.4的版本,本地编码没问题,response的content-type是空的.按html的mete解析的,查看源码也是 ...