poj1979

2023-10-08 03:48
文章标签 poj1979

本文主要是介绍poj1979,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

简单的dfs

#include <iostream>
#include <cstring>using namespace std;const int MAX_V = 25;int w, h, res;
char maze[MAX_V][MAX_V];
bool used[MAX_V][MAX_V];int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};struct node {int x;int y;
}nodes[MAX_V], start;int dfs(node v) {used[v.x][v.y] = true;for(int i=0; i<4; i++) {node n = {v.x + dx[i],v.y + dy[i]};if(!used[n.x][n.y] && n.x < h && 0 <= n.x && n.y < w && 0 <= n.y && maze[n.x][n.y] == '.') {res++;dfs(n);}}return res;
}int main() {freopen("in.txt", "r", stdin);while(~scanf("%d%d", &w, &h)) {if(w==0 && h==0)    break;getchar();memset(used, 0, sizeof(used));for(int i=0; i<h; i++) {for(int j=0; j<w; j++) {scanf("%c", &maze[i][j]);if(maze[i][j] == '@') {start.x = i;start.y = j;                    }if(maze[i][j] == '.')loc++;}getchar();}res = 1;printf("%d\n", dfs(start));}fclose(stdin);return 0;
}

这篇关于poj1979的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/162490

相关文章

HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) 解题报告

题目链接:HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9902    Accepted Submiss

poj1979 测试用例全通过,但提交就是WA,无解。

Hello,everybody,我是越爱越难,最近做POJ1979,提交时总是WA,所有的测试数据都通过了,我自己又反复看了几遍代码,感觉没毛病,扎心了!望老铁们来帮我一把!以下附上我写的Java代码。 import java.util.Scanner;public class CopyOfRedAndBlack {static int m,n;static char[][] c = new c

poj 2386 poj1562 poj1979 图的遍历 八个方向和四个方向 深搜

三个题基本上就是一样的思路,学到了怎么遍历四个方向和八个方向count初始化 poj1562#include<stdio.h>#include<string.h>int w,h;char a[105][105];void mi_gong(int x,int y){a[x][y]='*';int tempx;int tempy;for(int k=-1;k<=1;k++){for(in