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 ...
随机推荐
- timerWithTimeInterval 方法详用
1.初始化 + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelect ...
- HTTP/2笔记之流和多路复用
零.前言 本部分将讲解HTTP/2协议中对流的定义和使用,其实就是在说HTTP/2是若何做到多路复用的. 一.流和多路复用的关系 1. 流的概念 流(Stream),服务器和客户端在HTTP/2连接内 ...
- Eclipse常用快捷键 及 不格式化注释
eclipse不格式化注释 - [自写] 2007-08-15 刚才在Eclipse3.2上写东西,我写好的注释,整整齐齐的,我一格式化代码,就变得七七八八的了. 试着在Perferences ...
- 有限制的最短路spfa+优先队列
poj1724 ROADS Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10751 Accepted: 3952 De ...
- 遍历DataSet
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- python threading.thread
Thread 是threading模块中最重要的类之一,可以使用它来创建线程.有两种方式来创建线程:一种是通过继承Thread类,重写它的run方法:另一种是创建一个threading.Thread对 ...
- vs 开发常用快捷键
alt+shift+enter 编辑区最大化ctrl+] 括号匹配 ctrl+j 强迫智能感知ctrl+shift+空格 强迫智能感知(参数) ctrl+k+d ...
- MAVEN项目(仓库中没有jar包)
E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bajie\WEB-INF\lib 把jar包放 ...
- AE Scene开发中的观察者模式
AE SceneGraph中的观察者模式 注意SceneControl不是观察者,它只是一个SceneGraph的拥有者:SceneViewer才是观察者,SceneGraph是被观察对象,同时观察者 ...
- golang 复制对象的正确做法
需求 实际运用种,传参是一对象指针,现在如何最简便地复制一对象? 实现 坑:&* 先拿到值再指针? package main import ( "time" " ...