BZOJ1102: [POI2007] peaks and valleys grz

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 #defineMAXN 10057 using namespacestd;8 9 intn,sumx,sumy,ansx,ansy,hi[maxn][maxn],list[maxn*maxn][2],head,tail;Ten BOOLVIS[MAXN][MAXN]; One Const intdx[8]={-1,0,1,-1,1,-1,0,1}; A Const intdy[8]={-1,-1,-1,0,0,1,1,1}; - voidInitintx) { -      for(intI=1; i<=x;i++){ the          for(intj=1; j<=x;j++){ -scanf"%d",&hi[i][j]); -         } -     } + } - voidBFsintXinty) { +     inta,b,c,d; AHead=0, tail=1, list[tail][0]=x,list[tail][1]=y; sumx=sumy=0, vis[x][y]=1; at      while(head<tail) { -++head,a=list[head][0],b=list[head][1]; -          for(intI=0;i<8; i++){ -c=a+dx[i],d=b+Dy[i]; -             if(c>=1&&c<=n&&d>=1&&d<=N) { -                 if(hi[c][d]==hi[a][b]&&!Vis[c][d]) { invis[c][d]=1; -list[++tail][0]=c,list[tail][1]=D; to}Else{ +                     if(Hi[c][d]>hi[a][b]) sumx++; -                     if(Hi[c][d]; the                 } *             } $         }Panax Notoginseng     } - //printf ("%d%d%d%d\n", x,y,sumx,sumy); the     if(sumx==0&&sumy==0) ansx++,ansy++; +     Else if(sumx>0&&sumy>0)return; A     Else if(sumx>0) ansy++; the     Elseansx++; + } - intMain () { $scanf"%d",&n); $ init (n); -memset (Vis,0,sizeof(Vis)); -ansx=ansy=0; the      for(intI=1; i<=n;i++){ -          for(intj=1; j<=n;j++){Wuyi             if(vis[i][j]==1)Continue; the BFS (i,j); -         } Wu     } -printf"%d%d\n", Ansx,ansy); About     return 0; $}
View Code

Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1102

Practice: Prepare for NOIP. BFS can be.

BZOJ1102: [POI2007] peaks and valleys grz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.