【USACO】Space Exploration dfs

这篇博客介绍了如何使用DFS算法解决USACO中的空间探索问题,即在给定的N x N网格中统计相连的1 x 1的'asteroid'单元格形成的不同岛屿数量。通过提供一个10 x 10的示例地图和对应的DFS代码,博主解释了如何计算出整个空间区域中的独立asteroid数量。
摘要由CSDN通过智能技术生成

【USACO】Space Exploration
时间限制: 1.000 Sec 内存限制: 64 MB
题目描述:
Farmer John’s cows have finally blasted off from earth and are now floating around space in their Moocraft. The cows want to reach their fiery kin on Jupiter’s moon of Io, but to do this they must first navigate through the dangerous asteroid belt. Bessie is piloting the craft through this treacherous N x N (1 <= N <= 1,000) sector of space. Asteroids in this sector comprise some number of 1 x 1 squares of space-rock connected along their edges (two squares sharing only a corner count as two distinct asteroids). Please help Bessie maneuver through the field by counting the number of distinct asteroids in the entire sector. Consider the 10 x 10 space shown below on the left. The '*'s represent asteroid chunks, and each ‘.’ represents a .vast void of empty space. The diagram on the right shows an arbitrary numbering applied to the asteroids.

           ...**.....           ...11.....
           .*........           .2........
           ......*...           ......3...
           ...*..*...           ...3..3...
           ..*****...           ..33333...
           ...*......           ...3......
           ....***...           ....444...
           .*..***...           .5..444...
           .....*...*          ......4...6
           ..*.......          ..7........

It’s easy to see there are 7 asteroids in this sector.
/*
给出一张NN的地图(1 <= N <= 1,000),统计其中有多少座岛屿。下图为N=10时的地图,图中“”表示石块,“.”表示海水。
*/
输入:

  • Line 1: A single integer: N * Lines 2…N+1: Line i+1 contains row i of the asteroid field: N characters
    /*
    一行: 一个整数N
    2…N+1行: 每行有 N 个字符
    */
    输出:
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值