P2919 [USACO08NOV]守护农场Guarding the Farm
链接: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的更多相关文章
- bzoj1619 / P2919 [USACO08NOV]守护农场Guarding the Farm
P2919 [USACO08NOV]守护农场Guarding the Farm 相似题:P3456 [POI2007]GRZ-Ridges and Valleys 按海拔是否相同分块 每次bfs海拔相 ...
- 洛谷——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 ...
- 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 ...
- 一道并查集的(坑)题:关闭农场closing the farm
题目描述 in English: Farmer John and his cows are planning to leave town for a long vacation, and so FJ ...
随机推荐
- Unicode标准以及其常见的编码方案
目录 基本概念 码位 码位的类型 编码方案 UTF-32 UTF-16 UTF-8 参考资料 Unicode标准为每一个字符提供一个唯一的数字,而不用区分平台.语言等因素. The Unicode S ...
- <img>和background-img区别
1. 是否占位 background-image是背景图片,是css的一个样式,不占位 <img />是一个块状元素,它是一个图片,是html的一个标签,占位 2.否可操作 backgro ...
- Struts(四)
1.Struts 2提供了非常强大的类型转换功能,提供了多种内置类型转换器,也支持开发自定义类型转换器2.Struts 2框架使用OGNL作为默认的表达式语言 ==================== ...
- Pycharm如何快捷地交互式运行代码(>>>)
Pycharm如何快捷地交互式运行代码? 问题描述 在Pycharm直接一行行地交互运行已经写好的代码,不需要复制粘贴,怎么调出Pychram的交互式界面. 通过python自带的交互式界面 在搜索栏 ...
- 理解POP、OOP、AOP编程
一.面向过程编程:(POP:Procedure Oriented Programming) 面向过程编程是以功能为中心来进行思考和组织的一种编程方法,它强调的是功能(即系统的数据被加工和处理的过程), ...
- 《Python学习手册 第五版》 -第13章 while循环和for循环
上一章已经讲过if条件语句,这章重点是循环语句:while.for 本章的重点内容 1.while循环 1)一般形式 2)break.continue.pass和循环的else 2.for循环 1)一 ...
- Python学习框架(持续更新)
1.数据类型 整型:整数,1.2.3...这种 浮点型:简单理解就是小数,1.23.3.141572653等等 字符型:“这是字符”,简单说就是我们说的话,都可以作为字符 布尔值:只有2种,true. ...
- Thread.yield( )方法
Java线程中的Thread.yield( )方法,译为线程让步.顾名思义,就是说当一个线程使用了这个方法之后,它就会把自己CPU执行的时间让掉,让自己或者其它的线程运行,注意是让自己或者其他线程运行 ...
- Navicat Premium 12(破解版免安装)
获取安装包解压至任意位置 切勿更新!!! 切勿更新!!! 切勿更新!!! 扫下方二维码关注公众号回复:navicat12即可获取
- [C/C++]const限定符总结
const限定符 const是一种限定符,被const所限定的变量其值不可以被改变. const的初始化 由于const一旦创建其值就不能够被改变,所以我们必须对其进行初始化 const int a; ...