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 , ...
随机推荐
- c++中的string常用函数用法总结!
标准c++中string类函数介绍 注意不是CString 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而且作 ...
- 讨论几种数据列Column的特性(上)
之前笔者写过一个系列<索引列的usable和visible>(http://space.itpub.net/17203031/viewspace-688135),详细讨论了索引列的usab ...
- msp430入门学习23
msp430的ADC(模数转换) msp430入门学习
- [bzoj4994][Usaco2017 Feb]Why Did the Cow Cross the Road III_树状数组
Why Did the Cow Cross the Road III bzoj-4994 Usaco-2017 Feb 题目大意:给定一个长度为$2n$的序列,$1$~$n$个出现过两次,$i$第一次 ...
- School Marks-CodeForces
B. School Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 洛谷——P3379 【模板】最近公共祖先(LCA)
P3379 [模板]最近公共祖先(LCA) 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入输出格式 输入格式: 第一行包含三个正整数N.M.S,分别表示树的结点个数.询 ...
- 选择器的使用(nth-of-type和nth-last-of-type选择器)
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...
- Eclipse使用Maven时,修改默认中央仓库后的配置报错找不到包的问题解决
一般在公司内容配置Maven时会在settings.xml文件下配置私服nexus地址,那么修改完之后在Eclipse中如果不指定用户目录级别的settings.xml文件会出现找不到包的问题. se ...
- spring依赖注入中获取JavaBean
一.这个接口有什么用? 当一个类实现了这个接口(ApplicationContextAware)之后,这个类就可以方便获得ApplicationContext中的所有bean.换句话说,就是这个类可以 ...
- js 计算获取鼠标相对某个点的移动旋转角度
// 旋转角度 function getAngle(cen, first, second) { // cen : 中心点 [0,0] // first : 开始点 [1,3] // second : ...