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实现一个简单的DBMS(总结)
时间:2020/1/16 写这个DBMS(说DBMS夸张了,应该是一个控制台程序)的起因是数据库实践老师布置的一个大作业,先贴上GitHub地址: https://github.com/machi12 ...
- hashmap 的边遍历边存储
PS: Hashmap 的一边遍历边存储,可解决例如两数之和. 无重复最长子串问题等,代码为cpp格式. 以无重复最长子串为例. class Solution { public: int length ...
- Codeforces_462_B
http://codeforces.com/problemset/problem/462/B 简单的贪心,排序即可看出来. #include<cstdio> #include<ios ...
- Codeforces 1060C Maximum Subrectangle(子矩阵+预处理)
题意:给出数组a,b,组成矩阵c,其中$c_{ij}=a_i*b_j$,找出最的大子矩阵,使得矩阵元素和<=x,求这个矩阵的size n,m<=2000 思路:对于子矩阵(l1...r1) ...
- JS中map与forEach的区别
很多同学可能对于map与forEach的区别不是太了解,今天我们介绍一下JS中的map与forEach方法, 我对map的理解是,这个方法对一个数组arr1中的每一个元素进行遍历(传递给一个数组,参数 ...
- Leetcode题解 - 部分中等难度算法题解(56、957、825、781、1324、816)
957. N 天后的牢房 思路: 模拟变换,当N天结合后返回 => 当N非常大的时候,超时 => 一般N很大的时候,这种题目必然存在循环,所以记录找过的状态,一旦出现已经访问过的状态可立即 ...
- 文件传输协议-FTP
一.FTP概述 FTP(File Transfer Protocol 文件传输协议)C/S结构的应用层协议.由服务端和客户端两个部分共同实现文件传输功能 FTP服务器普遍部署于内网中,具有容易部署.方 ...
- 小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--& ...
- PHP在程序处理过程中动态输出内容
在安装discuz或其他一些开源产品的时候,在安装数据库时页面上的安装信息都是动态输出出来的,主要通过php两个函数来实现的, flush();ob_flush(); 代码如下 <html xm ...
- [转载]理解weight decay
http://blog.sina.com.cn/s/blog_a89e19440102x1el.html