bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场【bfs】
不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!!
是我看不懂人话还是翻译不说人话= =
把所有格子按值排个序,bfs扩展打标记即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int N=705,dx[]={-1,-1,-1,0,0,1,1,1},dy[]={-1,0,1,-1,1,-1,0,1};
int n,m,a[N][N],ans,tot;
bool v[N][N];
struct qwe
{
int x,y,w;
qwe(int X=0,int Y=0,int W=0)
{
x=X,y=Y,w=W;
}
}p[N*N];
bool cmp(const qwe &a,const qwe &b)
{
return a.w>b.w;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
inline bool ok(int x,int y,int pr)
{
return x>=1&&y>=1&&x<=n&&y<=m&&a[x][y]<=pr&&!v[x][y];
}
void bfs(qwe s)
{
ans++;
queue<qwe>q;
q.push(s);
v[s.x][s.y]=1;
while(!q.empty())
{
int x=q.front().x,y=q.front().y,w=q.front().w;
q.pop();
for(int i=0;i<8;i++)
if(ok(x+dx[i],y+dy[i],w))
v[x+dx[i]][y+dy[i]]=1,q.push(qwe(x+dx[i],y+dy[i],a[x+dx[i]][y+dy[i]]));
}
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
a[i][j]=read(),p[++tot]=qwe(i,j,a[i][j]);
sort(p+1,p+1+tot,cmp);
for(int i=1;i<=tot;i++)
if(!v[p[i].x][p[i].y])
bfs(p[i]);
printf("%d\n",ans);
return 0;
}
bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场【bfs】的更多相关文章
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1619 题意: 给你一个n*m的地形图,位置(x,y)的海拔为h[x][y]. 一个山顶的定 ...
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 498 Solve ...
- 【BZOJ】1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1619 首先不得不说,,题目没看懂.... 原来就是找一个下降的联通块.... 排序后dfs标记即可. ...
- bzoj1619[Usaco2008 Nov]Guarding the Farm 保卫牧场
Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...
- [Usaco2008 Nov]Guarding the Farm 保卫牧场[DFS]
Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...
- BZOJ 1229: [USACO2008 Nov]toy 玩具
BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...
- BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )
二分一下答案就好了... --------------------------------------------------------------------------------------- ...
- BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛( dp )
状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) = Σ dp( i , S - { i } ) ( i ∈ S , ...
随机推荐
- Webdriver元素定位1
元素的定位应该是自动化测试的核心,要想操作一个元素,首先应该识别这个元素. webdriver提供了一系列的元素定位方法,常用的有以下几种: id name class name tag link t ...
- [codevs3044][POJ1151]矩形面积求并
[codevs3044][POJ1151]矩形面积求并 试题描述 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入 可能有多组数据,读到n=0为止(不超过15组) 每组数据第一行一个数n ...
- hdu 1075
#include<stdio.h> #include<string.h> #include<string> #include<iostream> #in ...
- 什么是单点登录(SSO)
前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 在我实习之前我就已经在看单点登录的是什么了,但是实习 ...
- hbase definitive guide 笔记
ext3 file system 优化 ext3 在用在hbase上可以做如下优化: 1. mount的时候加上noatime选项.这可以减少管理开销 2. 用命令tune2fs -m 0 /dev/ ...
- 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise
题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chine ...
- Windows TAKEOWN & ICACLS
TAKEOWN:takeown /f 文件名 获取该文件的所属权takeown /f /r /d n 文件夹 获取整个文件夹及其下面子目录文件的所属权 TAK ...
- SSD硬盘安装系统后要做的事
1***cmd>fsutil behavior query DisableDeleteNotify 0如果返回值是0,则代表TRIM处于开启状态:反之如果返回值是1,则代表TRIM处于关闭状态2 ...
- Eclipse中的Web项目自己主动部署到Tomcat以及怎样在Eclipse中使用My Eclipseproject
我是一个新手学习Java,servlet和Jsp. 痛苦的是我时候一个.net程序猿,习惯了微软的VS IDE一切都是封装好的.傻瓜式的使用, 不须要关心内部实现. 悲催的是我看到资料都是My Ecl ...
- C语言之函数调用17—递归法之中的一个般函数的调用(2)
//递归法 /* ================================================================== 题目:求F(60),当中F(n)定义例如以下: ...