Oil Deposits
描述
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
输入
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.
输出
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
input:
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
output:
0
1
2
2
问题描述:在一个网格矩阵中寻找不同油矿 , 当遇到“@”时 , 这个点上 下 左 右 斜角上是“@”的点属于同一个油矿。
第一个想法:广搜 和 深搜
决定深搜递归解决.
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
char grid[101][101];
bool flag[101][101];
int dir[][2] = {{-1,1} , {0,1} , {1,1} , {1,0} , {1,-1} , {0,-1} , {-1,-1} , {-1,0}};
void DFS(int x,int y,int m,int n)
{
}
int main()
{
return 0;
}
Hero In Maze
描述
500年前,Jesse是我国最卓越的剑客。他英俊潇洒,而且机智过人^_^。
突然有一天,Jesse心爱的公主被魔王困在了一个巨大的迷宫中。Jesse听说这个消息已经是两天以后了,他知道公主在迷宫中还能坚持T天,他急忙赶到迷宫,开始到处寻找公主的下落。
时间一点一点的过去,Jesse还是无法找到公主。最后当他找到公主的时候,美丽的公主已经死了。从此Jesse郁郁寡欢,茶饭不思,一年后追随公主而去了。T_T
500年后的今天,Jesse托梦给你,希望你帮他判断一下当年他是否有机会在给定的时间内找到公主。
他会为你提供迷宫的地图以及所剩的时间T。请你判断他是否能救出心爱的公主。
输入
题目包括多组测试数据。
每组测试数据以三个整数N,M,T(0<n, m≤20, t>0)开头,分别代表迷宫的长和高,以及公主能坚持的天数。
紧接着有M行,N列字符,由".","*","P","S"组成。其中
"." 代表能够行走的空地。
"*" 代表墙壁,Jesse不能从此通过。
"P" 是公主所在的位置。
"S" 是Jesse的起始位置。
每个时间段里Jesse只能选择“上、下、左、右”任意一方向走一步。
输入以0 0 0结束。
输出
如果能在规定时间内救出公主输出“YES”,否则输出“NO”。
样例输入
4 4 10
....
....
....
S**P
0 0 0
样例输出
YES 第一想法:广搜遍历
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int max = 100;
int ans[max][max];
char map[max][max];
int dir[][2]={{0,1},{0,-1},{1,0},{-1,0}};
int n , m , day , i , j;
struct node
{
};
int bfs(node s,node e)
{
}
}
int main()
{
}