不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!!

是我看不懂人话还是翻译不说人话= =

把所有格子按值排个序,bfs扩展打标记即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<queue>
  5. using namespace std;
  6. const int N=705,dx[]={-1,-1,-1,0,0,1,1,1},dy[]={-1,0,1,-1,1,-1,0,1};
  7. int n,m,a[N][N],ans,tot;
  8. bool v[N][N];
  9. struct qwe
  10. {
  11. int x,y,w;
  12. qwe(int X=0,int Y=0,int W=0)
  13. {
  14. x=X,y=Y,w=W;
  15. }
  16. }p[N*N];
  17. bool cmp(const qwe &a,const qwe &b)
  18. {
  19. return a.w>b.w;
  20. }
  21. int read()
  22. {
  23. int r=0,f=1;
  24. char p=getchar();
  25. while(p>'9'||p<'0')
  26. {
  27. if(p=='-')
  28. f=-1;
  29. p=getchar();
  30. }
  31. while(p>='0'&&p<='9')
  32. {
  33. r=r*10+p-48;
  34. p=getchar();
  35. }
  36. return r*f;
  37. }
  38. inline bool ok(int x,int y,int pr)
  39. {
  40. return x>=1&&y>=1&&x<=n&&y<=m&&a[x][y]<=pr&&!v[x][y];
  41. }
  42. void bfs(qwe s)
  43. {
  44. ans++;
  45. queue<qwe>q;
  46. q.push(s);
  47. v[s.x][s.y]=1;
  48. while(!q.empty())
  49. {
  50. int x=q.front().x,y=q.front().y,w=q.front().w;
  51. q.pop();
  52. for(int i=0;i<8;i++)
  53. if(ok(x+dx[i],y+dy[i],w))
  54. v[x+dx[i]][y+dy[i]]=1,q.push(qwe(x+dx[i],y+dy[i],a[x+dx[i]][y+dy[i]]));
  55. }
  56. }
  57. int main()
  58. {
  59. n=read(),m=read();
  60. for(int i=1;i<=n;i++)
  61. for(int j=1;j<=m;j++)
  62. a[i][j]=read(),p[++tot]=qwe(i,j,a[i][j]);
  63. sort(p+1,p+1+tot,cmp);
  64. for(int i=1;i<=tot;i++)
  65. if(!v[p[i].x][p[i].y])
  66. bfs(p[i]);
  67. printf("%d\n",ans);
  68. return 0;
  69. }

bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场【bfs】的更多相关文章

  1. BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 491  S ...

  2. BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1619 题意: 给你一个n*m的地形图,位置(x,y)的海拔为h[x][y]. 一个山顶的定 ...

  3. 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 498  Solve ...

  4. 【BZOJ】1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场(dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1619 首先不得不说,,题目没看懂.... 原来就是找一个下降的联通块.... 排序后dfs标记即可. ...

  5. bzoj1619[Usaco2008 Nov]Guarding the Farm 保卫牧场

    Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...

  6. [Usaco2008 Nov]Guarding the Farm 保卫牧场[DFS]

    Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...

  7. BZOJ 1229: [USACO2008 Nov]toy 玩具

    BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...

  8. BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )

    二分一下答案就好了... --------------------------------------------------------------------------------------- ...

  9. BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛( dp )

    状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) =  Σ dp( i , S - { i } )  ( i ∈ S , ...

随机推荐

  1. GitHub & puppeteer & Chinese character & bug

    GitHub & puppeteer & Chinese character & bug https://github.com/GoogleChrome/puppeteer/b ...

  2. codevs——1019 集合论与图论

    1019 集合论与图论  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 集合论与图论对于小松来说 ...

  3. JSTL-函数标签库

    主页:http://www.cnblogs.com/EasonJim/p/6958992.html的分支页. 一.fn:contains() fn:contains()函数决定了一个输入字符串是否包含 ...

  4. TensorFlow-GPU环境配置之二——CUDA环境配置

    1.安装最新显卡驱动 到系统设置->软件和更新->附加驱动中选中最新的显卡驱动,并应用 2.下载CUDA8.0 https://developer.nvidia.com/cuda-down ...

  5. symfony could not load type 'datetime'

    当用curd生成控制器后,当修改的时候,会有这个提示,解决方法 在orm中通过事务的方式填充时间,然后把生成的form中的文件的时间段去掉 $builder ->add('title') -&g ...

  6. clamav完整查杀linux病毒实战(摘抄)

    http://dadloveu.blog.51cto.com/blog/715500/1882521 Linux服务器一直给我们的印象是安全.稳定.可靠,性能卓越.由于一来Linux本身的安全机制,L ...

  7. EC2的维护更新-总结篇及有效经验分享

    2014年10月11日 号,我们对不到10%的EC2实例的完毕了重新启动.来预防不论什么与Xen安全通报(XSA-108)相关的安全风险. 日之前都有义务遵守相关问题的保密要求.直到它被向公众公布. ...

  8. Num 15: NYOJ: 题目0002 : 括号配对问题 [ 栈(stack) ]

    原题连接      首先要了解有关栈的一些基本知识,即:      什么是栈,栈有什么作用:        1.什么是栈: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...

  9. 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 ...

  10. kafka 生产者消费者 api接口

    生产者 import java.util.Properties; import kafka.javaapi.producer.Producer; import kafka.producer.Keyed ...