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 , ...
随机推荐
- GitHub & puppeteer & Chinese character & bug
GitHub & puppeteer & Chinese character & bug https://github.com/GoogleChrome/puppeteer/b ...
- codevs——1019 集合论与图论
1019 集合论与图论 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 集合论与图论对于小松来说 ...
- JSTL-函数标签库
主页:http://www.cnblogs.com/EasonJim/p/6958992.html的分支页. 一.fn:contains() fn:contains()函数决定了一个输入字符串是否包含 ...
- TensorFlow-GPU环境配置之二——CUDA环境配置
1.安装最新显卡驱动 到系统设置->软件和更新->附加驱动中选中最新的显卡驱动,并应用 2.下载CUDA8.0 https://developer.nvidia.com/cuda-down ...
- symfony could not load type 'datetime'
当用curd生成控制器后,当修改的时候,会有这个提示,解决方法 在orm中通过事务的方式填充时间,然后把生成的form中的文件的时间段去掉 $builder ->add('title') -&g ...
- clamav完整查杀linux病毒实战(摘抄)
http://dadloveu.blog.51cto.com/blog/715500/1882521 Linux服务器一直给我们的印象是安全.稳定.可靠,性能卓越.由于一来Linux本身的安全机制,L ...
- EC2的维护更新-总结篇及有效经验分享
2014年10月11日 号,我们对不到10%的EC2实例的完毕了重新启动.来预防不论什么与Xen安全通报(XSA-108)相关的安全风险. 日之前都有义务遵守相关问题的保密要求.直到它被向公众公布. ...
- Num 15: NYOJ: 题目0002 : 括号配对问题 [ 栈(stack) ]
原题连接 首先要了解有关栈的一些基本知识,即: 什么是栈,栈有什么作用: 1.什么是栈: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...
- Cookies 初识 Dotnetspider EF 6.x、EF Core实现dynamic动态查询和EF Core注入多个上下文实例池你知道有什么问题? EntityFramework Core 运行dotnet ef命令迁移背后本质是什么?(EF Core迁移原理)
Cookies 1.创建HttpCookies Cookie=new HttpCookies("CookieName");2.添加内容Cookie.Values.Add(&qu ...
- kafka 生产者消费者 api接口
生产者 import java.util.Properties; import kafka.javaapi.producer.Producer; import kafka.producer.Keyed ...