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