链接: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. python学习Day06--编码

    [主要内容] 1. is 和 == 区别 id()函数 == 判断两边的值 is 判断内存地址回顾编码: 1. ASCII: 英文, 特殊字符, 数字, 8bit, 1byte 2. GBK: 中文 ...

  2. (数据科学学习手札75)基于geopandas的空间数据分析——坐标参考系篇

    本文对应代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在上一篇文章中我们对geopandas中的数据结 ...

  3. 9. Palindrome Number QuestionEditorial Solution

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  4. SpringBoot之ApplicationRunner接口和@Order注解

    我们在开发中可能会有这样的情景.需要在容器启动的时候执行一些内容.比如读取配置文件,数据库连接之类的.SpringBoot给我们提供了ApplicationRunner接口来帮助我们实现这种需求.该接 ...

  5. 实例演示:如何在Kubernetes上大规模运行CI/CD

    本周四晚上8:30,第二期k3s在线培训如约开播!本期课程将介绍k3s的核心架构,如高可用架构以及containerd.一起来进阶探索k3s吧! 报名及观看链接:http://z-mz.cn/PmwZ ...

  6. vue项目实战经验汇总

    目录 1.vue框架使用注意事项和经验 1.1 解决Vue动态路由参数变化,页面数据不更新 1.2 vue组件里定时器销毁问题 1.3 vue实现按需加载组件的两种方式 1.4 组件之间,父子组件之间 ...

  7. postman之下载文件

    前言 小伙伴们在实际的测试工作中是否遇到过下载的接口呢,例如网盘的项目就涉及到上传和下载的接口了,那么我们如何利用postman对下载接口进行测试呢?下面我们一起来学习吧! 练习案例:下载接口:htt ...

  8. 二叉树的非递归遍历C++实现

    #include<iostream> #include<stdlib.h> #define maxsize 100 using namespace std; typedef s ...

  9. Golang的sync.WaitGroup 实现逻辑和源码解析

    在Golang中,WaitGroup主要用来做go Routine的等待,当启动多个go程序,通过waitgroup可以等待所有go程序结束后再执行后面的代码逻辑,比如: func Main() { ...

  10. 前端添加复选框checkbox 提交到django后台处理

    根据前端勾选的复选框 提交勾选的数据到后台处理 che.html <!DOCTYPE html> <html lang="en"> <head> ...