Swust OJ 001 Satellite Photographs

本文介绍了一种使用DFS算法处理卫星照片来寻找最大连续牧场区域的方法。通过递归地探索相邻像素,该算法能够有效地确定牧场的最大面积。

Farmer John purchased satellite photos of W x H pixels of his farm (1 <= W <= 80, 1 <= H <= 1000) and wishes to determine the largest 'contiguous' (connected) pasture. Pastures are contiguous when any pair of pixels in a pasture can be connected by traversing adjacent vertical or horizontal pixels that are part of the pasture. (It is easy to create pastures with very strange shapes, even circles that surround other circles.) 

Each photo has been digitally enhanced to show pasture area as an asterisk ('*') and non-pasture area as a period ('.'). Here is a 10 x 5 sample satellite photo: 

..*.....** 
.**..***** 
.*...*.... 
..****.*** 
..****.***
 

This photo shows three contiguous pastures of 4, 16, and 6 pixels. Help FJ find the largest contiguous pasture in each of his satellite photos.

Description

* Line 1: Two space-separated integers: W and H 
* Lines 2..H+1: Each line contains W "*" or "." characters representing one raster line of a satellite photograph.


 

Input

* Line 1: The size of the largest contiguous field in the satellite photo.

Output
1
2
3
4
5
6
7
10 5
..*.....**
.**..*****
.*...*....
..****.***
..****.***
Sample Input
1
2
16
Sample Output
/
/*
 *  求连在一起的*号最多有多少- - 
 *  dfs bfs 都行 这里用dfs(谁叫他写起来代码短呢。。)
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <cmath>
#include <queue>
using namespace std;
int dir[4][2] = { {-1,0}, {0,1}, {0,-1}, {1,0} };
char map[81][1001];
bool vis[81][1001];
int col, row;
int cnt = 0;
void dfs(int i,int j) {
	for (int k = 0; k < 4; k++) {
		int x = i + dir[k][0];
		int y = j + dir[k][1];
		if (x>=0 && x<row && y>=0 && y<col ) {
			if (map[x][y] == '*' && !vis[x][y]) {
				cnt++;
				vis[x][y] = 1;
				dfs(x, y);
			}
		}
	}
}
int main(){
	int ans = 0;
		cin >> col >> row;
		for (int i = 0; i < row; i++)
			for (int j = 0; j < col; j++) {
				cin >> map[i][j];
			}
		for (int i = 0; i < row; i++)
			for (int j = 0; j < col; j++) {
				if (map[i][j] == '*') {
					vis[i][j] = 1;
					cnt = 1;
					dfs(i, j);
					if (cnt > ans)
						ans = cnt;
				}
			}
		cout << ans << endl;
	return 0;
}




                
### SWUST OJ Problem 32 Information and Solution Unfortunately, specific details about SWUST OJ problem number 32 are not directly provided in the available references. However, based on similar problems from this platform such as those mentioned in other citations, a general approach to solving typical programming challenges can be outlined. #### Understanding Common Elements of Programming Problems on SWUST OJ Platform Problems like SWUSTOJ276, SWUSTOJ77, SWUSTOJ78, SWUSTOJ1286, and SWUSTOJ1285 emphasize proper use of `if` and `else` statements along with maintaining good coding practices including appropriate formatting[^1]. For instance, when dealing with numerical outputs, `%g` is used for automatic selection between fixed-point notation (`%f`) or scientific notation (`%e`), depending on which provides more compact output without loss of precision. Given that detailed specifics regarding problem 32 aren't present here, one should look at common patterns found across different types of questions posed by platforms like these: - **Input Handling**: Typically involves reading inputs either single values or arrays/lists. - **Logic Implementation**: Applying algorithms ranging from simple arithmetic operations up through complex data structures manipulation. - **Output Formatting**: Ensuring results adhere strictly to specified formats using placeholders like `%d`, `%s`, etc., where applicable. Since no direct reference exists specifically addressing SWUST OJ problem 32 within given sources, consider exploring adjacent numbered problems around it for clues about its nature—whether mathematical computation, string processing, dynamic programming elements, et cetera—and adapt solutions accordingly while keeping best practice guidelines intact. ```c // Example C code snippet demonstrating basic structure often seen in contest-style programs #include <stdio.h> int main() { int n; scanf("%d", &n); // Read input value if (condition_based_on_problem_statement) { printf("Result under condition A\n"); } else { printf("Alternative result\n"); } return 0; } ``` --related questions-- 1. How does understanding how `%g` works help improve program efficiency? 2. What strategies could apply towards optimizing performance in competitive programming contests? 3. Can you provide examples illustrating effective usage of conditional operators (`if`, `else`) in algorithm design?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值