bzoj1102: [POI2007]山峰和山谷Grz

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 1005
using namespace std; int n,sumx,sumy,ansx,ansy,hi[maxn][maxn],list[maxn*maxn][],head,tail;
bool vis[maxn][maxn];
const int dx[]={-,,,-,,-,,};
const int dy[]={-,-,-,,,,,};
void init(int x){
for (int i=;i<=x;i++){
for (int j=;j<=x;j++){
scanf("%d",&hi[i][j]);
}
}
}
void bfs(int x,int y){
int a,b,c,d;
head=,tail=,list[tail][]=x,list[tail][]=y; sumx=sumy=,vis[x][y]=;
while (head<tail){
++head,a=list[head][],b=list[head][];
for (int i=;i<;i++){
c=a+dx[i],d=b+dy[i];
if (c>=&&c<=n&&d>=&&d<=n){
if (hi[c][d]==hi[a][b]&&!vis[c][d]){
vis[c][d]=;
list[++tail][]=c,list[tail][]=d;
}else{
if (hi[c][d]>hi[a][b]) sumx++;
if (hi[c][d]<hi[a][b]) sumy++;
}
}
}
}
// printf("%d %d %d %d\n",x,y,sumx,sumy);
if (sumx==&&sumy==) ansx++,ansy++;
else if (sumx>&&sumy>) return;
else if (sumx>) ansy++;
else ansx++;
}
int main(){
scanf("%d",&n);
init(n);
memset(vis,,sizeof(vis));
ansx=ansy=;
for (int i=;i<=n;i++){
for (int j=;j<=n;j++){
if (vis[i][j]==) continue;
bfs(i,j);
}
}
printf("%d %d\n",ansx,ansy);
return ;
}

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1102

做法:为noip做准备。bfs即可。

上一篇:数据绑定时(<%#Eval)单引号双引号嵌套问题


下一篇:获取当前运行dll文件的路径