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 ...
随机推荐
- Java 程序是如何执行的
Java 程序是如何执行的 了解任何一门语言的精髓都是先俯览其全貌,从宏观的视角把握全局,然后再深入每个知识点逐个击破,这样就可以深入而快速的掌握一项技能.同样学习 Java 也是如此,本节就让我们先 ...
- js之split()和join()的用法
说明 这几天写了一个简单的vue项目,需要截取字符串,一时间想到了正则表达式,还折腾了还一会儿,最后上网查了一下,使用split()再简单不过了,也顺便回忆一下join().可见我有多菜,哈哈,学了这 ...
- JDK的下载及安装教程图解(超详细哦~)
一.本人电脑系统介绍及JDK下载途径 1.先说明一下我的电脑为win10系统,64位操作系统~ 2.我选择下载的JDK版本为1.8版本.给大家来两个下载渠道,方便大家的下载~ JDK官网:https: ...
- Scala 学习(8)之「trait (2) 」
trait调用链 Scala 中支持让类继承多个 trait 后,依次调用多个 trait 中的同一个方法,只要让多个 trait 的同一个方法中,在最后都执行super.方法即可 类中调用多个 tr ...
- Windows下SVN权限配置
Windows下SVN权限配置 按照前面的教程装完1.6.1版以后,当svnadmin create D;\svn创建仓库后,应该在仓库目录下的config目录有3个文件— auth ...
- Intellij idea智能提示设置
忽略大小写敏感: 打开设置(CTRL+ALT+S)搜索editor,找到"Code Completion"->点击Case sensitive completion后面的选择 ...
- CCF_ 201409-2_画图
将一个数组比作画板,有颜色的位置标1,统计即可. #include<cstdio> #include<iostream> #define NUM 100 using names ...
- 51nod 1133 不重叠的线段 (贪心,序列上的区间问题)
题意: 最多能选几条不重叠的线段 思路: 按R从小到大排序,维护一个最大的右端点 右端点最小的那个线段是必选的,可以贪心地证明 代码: #include<iostream> #includ ...
- HDU 6186 CS Course (连续位运算)
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Request库的安装与使用
Request库的安装与使用 安装 pip install reqeusts Requests库的7个主要使用方法 requests.request() 构造一个请求,支撑以下各方法的基础方法 req ...