链接:P2919

-----------------------------------

一道非常暴力的搜索题

-----------------------------------

注意的是,我们要从高出往低处搜,所以要sort一边

然后没有什么值得成为绿题的部分了

绝对是恶评

-----------------------------------

题面有歧义,我们在搜索的时侯扩展的条件是<=,不是等于

-----------------------------------

#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct so{
int x;
int y;
int v;
}s[];
int ma[][];
bool cmp(so x,so y){
return x.v>y.v;
}
int vis[][];
int x,y,n,m,now;
int ans;
int p;
int xc[]={,,,-,-,-,,};
int yc[]={,,,,,-,-,-};
void dfs(int x,int y){
if(x<||y<||x>n||y>m){
return ;
}
vis[x][y]=;
for(int i=;i<=;++i){
if(ma[x+xc[i]][y+yc[i]]<=ma[x][y]&&!vis[x+xc[i]][y+yc[i]])
dfs(x+xc[i],y+yc[i]);
}
return ; }
int main(){
cin>>n>>m;
for(int i=;i<=n;++i){
for(int j=;j<=m;++j){
scanf("%d",&now);
ma[i][j]=now;
p++;
s[p].x=i;
s[p].y=j;
s[p].v=now;
}
}
sort(s+,s+p+,cmp);
for(int i=;i<=p;++i){
if(!vis[s[i].x][s[i].y]){
ans++;
dfs(s[i].x,s[i].y);
}
} cout<<ans;
return ; }

Ac

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

  1. bzoj1619 / P2919 [USACO08NOV]守护农场Guarding the Farm

    P2919 [USACO08NOV]守护农场Guarding the Farm 相似题:P3456 [POI2007]GRZ-Ridges and Valleys 按海拔是否相同分块 每次bfs海拔相 ...

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

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

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

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

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

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

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

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

  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. 一道并查集的(坑)题:关闭农场closing the farm

    题目描述 in English: Farmer John and his cows are planning to leave town for a long vacation, and so FJ ...

随机推荐

  1. LESS 用法入门

    本文旨在加深对 LESS 的理解和记忆,供自己开发时参考.相信对没有接触过 LESS 的程序员还是有用的,大佬绕路. 一. 安装和使用 LESS 1.1 安装 使用命令行安装 LESS npm ins ...

  2. 时序数据库 Apache-IoTDB 源码解析之文件格式简介(三)

    上一章聊到在车联网或物联网中对数据库的需求,以及 IoTDB 的整体架构,详情请见: 时序数据库 Apache-IoTDB 源码解析之系统架构(二) 打一波广告,欢迎大家访问IoTDB 仓库,求一波 ...

  3. CSS颜色表示的几种方式

    在CSS中颜色有很多表示方式,今天列出一些常见的颜色表示方式及它们的用法. ①color:blue;  第一种,调用颜色属性,将颜色的英文输入在冒号后,以分号结束. 这种方法直接了当,但是能表示的颜色 ...

  4. PAT_B数素数 (20)

    数素数 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 令Pi表示第i个素数.现任给两个正整数M &l ...

  5. TensorFlow 中的张量,图,会话

    tensor的含义是张量,张量是什么,听起来很高深的样子,其实我们对于张量一点都不陌生,因为像标量,向量,矩阵这些都可以被认为是特殊的张量.如下图所示: 在TensorFlow中,tensor实际上就 ...

  6. Codeforces_825

    A.连续1的个数,0用来分割,注意连续的0. #include<bits/stdc++.h> using namespace std; int n; string s; int main( ...

  7. JavaScript 与 Java 有什么不同?

    JavaScript 编程语言是由 Netscape,Inc. 开发的,它并不是 Java 平台的一部分. JavaScript 不会创建小应用程序或独立应用程序.在最常见的形式中,JavaScrip ...

  8. How to do if sqlserver table identity column exceed limited ?

    script: select a.TABLE_NAME,a.COLUMN_NAME,a.DATA_TYPE, (CASE a.DATA_TYPE when 'int' then 'limited be ...

  9. vue的组件传值

    1.父组件向子组件传值 父组件: 123456789101112 <template> <child :name="name"></child> ...

  10. php gettype()函数

      gettype() 会根据 参数类型返回值: boolean:表示变量为布尔类型 integer:表示变量为整数类型 double :表示变量为float类型(历史原因) string:表示变量为 ...