本文主要是介绍poj_1164_递归,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目描述:
解题思路:
代码:
#include <stdio.h> #include <stdlib.h> #define N 51typedef struct{int w,n,e,s; }ROOM; //有墙则置为1, 无墙为0 ROOM room[N][N]; int f[N][N], s, max, count, m, n;void find(int i, int j) {if(f[i][j] >0 ){;}else{s++;f[i][j] = count + 1;//四个方向 if(room[i][j].w == 0)find(i,j-1);if(room[i][j].n == 0)find(i-1,j);if(room[i][j].s == 0)find(i+1,j);if(room[i][j].e == 0)find(i,j+1);} } main() {int i,j,v;scanf("%d %d",&m, &n);for(i=0;i<m;i++)for(j=0;j<n;j++){scanf("%d",&v);room[i][j].s = v/8;v = v%8;room[i][j].e = v/4;v = v%4;room[i][j].n = v/2;v = v%2;room[i][j].w = v/1;}memset(f,0,sizeof(f));max = 0;count = 0;for(i=0;i<m;i++){for(j=0;j<n;j++){if(f[i][j]==0){s = 0;find(i,j);count ++;}if(s>max)max = s;}}printf("%d\n",count);printf("%d\n",max);//system("pause");return 0; }
这篇关于poj_1164_递归的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!