随笔分类 -  DFS(深度优先搜索)

杭电 1241 Oil Deposits
摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>int n,m;int hash[105][105];char map[105][105];int isok(int i,int j){ if(i>=0&&i<n&&j>=0&&j<m&&map[i][j]=='@'&&!hash[i][j]) return 1; return 0;}void DFS(int x,int y){ has 阅读全文
posted @ 2011-09-25 21:58 枫叶飘泪 阅读(411) 评论(0) 推荐(0)
杭电 1312 Red and Black
摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>int n,m;int hash[30][30];char map[30][30];void DFS(int x,int y){ if(x>n||y>m||hash[x][y]||map[x][y]=='#') return; hash[x][y]=1; DFS(x-1,y); DFS(x+1,y); DFS(x,y-1); DFS(x,y+1);}int main(){ while(scanf("%d%d%*c&q 阅读全文
posted @ 2011-09-25 21:19 枫叶飘泪 阅读(450) 评论(0) 推荐(0)
杭电 2952 Counting Sheep
摘要:#include<stdio.h>#include<string.h>#include<stdlib.h>int n,m;char map[105][105];int hash[105][105];int isok(int i,int j){ if(i>=0&&i<n&&j>=0&&j<m&&map[i][j]=='#'&&!hash[i][j]) { return 1; } return 0;}void DFS(int x,int y){ 阅读全文
posted @ 2011-09-25 19:54 枫叶飘泪 阅读(252) 评论(0) 推荐(0)