hdu1547 火拼泡泡龙 bfs

这篇博客介绍了如何解决HDU1547火拼泡泡龙问题,通过BFS算法寻找同色球并计算消除数量。当找到的同色球数量小于3时,输出0;否则,将这些球标记为'已消除',并从总球数中减去能够悬挂的球数,得出消除和掉落的球数。文章还详细讨论了奇偶行球的坐标计算规则,并提供了示例和代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Bubble Shooter

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 176 Accepted Submission(s): 69
 
Problem Description

Bubble shooter is a popular game. You can find a lot of versions from the Internet.

The goal of this game is to clean the bubbles off the field. Every time you just point the cannon to where you want the next bubble to go, and if three or more of bubbles with the same color came together (including the newly shot bubble), they will detonate. After the first explode, if some bubbles are disconnected from the bubble(s) in the topmost row, they will explode too.

In this problem, you will be given an arranged situation of bubbles in the field and the newly shot bubble. Your program should output the total number of bubbles that will explode.

Input
There are multiple test cases. Each test case begins with four integers H (the height of the field, 2 <= H <= 100), W (the width of the field, 2 <= W <= 100, in the picture above, W is 10), h (the vertical position of the newly shot bubble, count from top to bottom, and the topmost is counted as 1) and w (the horizontal position of the newly shot bubble, count from left to right, and the leftmost is counted as 1).
Then H lines follow, the odd lines will contain W characters while the even lines will contain W-1 characters (refer to the picture above). Each character will be either a lowercase from ‘a’ to ‘z’ indicating the color of the bubble in that position, or a capital letter ‘E’ indicating an empty position. You may assure the arranged situation is always valid (all the bubbles are directly or indirectly connected with at least one bubble in the topmost row, and the position of newly shot bubble is never empty).
Output
For each test case, output an integer indicating how many bubbles will explode.
Sample Input
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值