博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1547 Bubble Shooter(BFS蔓延模拟)
阅读量:4137 次
发布时间:2019-05-25

本文共 3465 字,大约阅读时间需要 11 分钟。

Bubble Shooter

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 991 Accepted Submission(s): 419
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
2 2 2 1aaa3 3 3 3aaababba3 3 3 1aaababba3 3 3 3aaaEaaab
Sample Output
3830
Author
JIN, Tianpeng
Source
/*题目意思是: 给你一个H*W的矩阵,奇数行w个,偶数行w-1个字符,E代表空,a-z代表的不同的颜色,给你一个起始坐标h,w,作为新射进去的泡泡,如果周围连着有三个(算上自己),则连着的一起爆炸,如果剩下的没连着顶行也会掉下来,问有多少掉下来 网上注解:题意:其实就是泡泡龙的游戏,给你起始的地图,以及刚打出去的泡泡的位置,如果与刚打出的泡泡相连的泡泡数大于等于3,则相连的相同颜色的泡泡会掉下来,之后,没有与顶层泡泡直接或间接相连的泡泡也会掉下来。问掉下来的泡泡总数。 *//*思路:对起始泡泡进行广搜,标记,然后枚举顶层存在的泡泡广搜进行染色,剩下的和刚才爆炸的即为掉下来的 注意:坑死我了!!
奇偶行的连接点并不一样啊 看图!!!和下面的分析!*/#include
#include
#include
using namespace std;const int N=100+5;char map[N][N];bool book[N][N];int re;struct Node{ int x,y;}node,tmp;queue
q;//方向错了!这里要看图 排列的时候是交叉的//例如偶数行时/*0 1 10 X 11 1 1//奇数行时1 1 01 X 11 1 0*/int step2[6][2]={
{-1,0},{-1,1},{0,-1},{0,1},{1,0},{1,1}}; //oddint step1[6][2]={
{-1,-1},{-1,0},{0,-1},{0,1},{1,-1},{1,0}};int main(){ int n,m,x,y; while(cin>>n>>m>>x>>y){ re=0; while(!q.empty()) q.pop(); memset(book,0,sizeof(book)); for(int i=0;i
>map[i]; if((i+1)%2==0) map[i][m-1]='E'; } /*for(int i=0;i
=n||b>=m) continue; if(book[a][b]||map[a][b]=='E') continue; if(map[a][b]!=map[tmp.x][tmp.y]) continue; re++; node.x=a; node.y=b; book[a][b]=1; q.push(node); } } //注意 //注意 //注意 //如果有3个或以上泡泡爆炸,则继续,否则结束 //- _ -!! 这种做法是错误的? //因为1) num<3 。 //那么要将之前的标记清除, //找出与顶层泡泡直接相连或间接相连的泡泡总数ans, //all-ans就是答案了。这里解决了一个特殊情况, // 本来以为num<3的话,直接输出0就可以了,但其实很有可能, // 即使num<3,但起始的地图也会有一些泡泡会掉下来。 if(re<3) { //cout<<0<
=n||a<0||b<0||b>=m) continue; if(book[a][b]||map[a][b]=='E') continue; book[a][b]=1; node.x=a; node.y=b; q.push(node); } } } } //查找剩下的 for(int i=0;i

转载地址:http://fdmvi.baihongyu.com/

你可能感兴趣的文章
赖世雄精准美国英语音标发音指南03 (附我备注)
查看>>
赖世雄精准美国英语音标发音指南04(附我备注)
查看>>
《过得刚好》 郭德纲
查看>>
fork函数详解(fork就是分叉的意思, 很形象)
查看>>
那一年, fork() 函数弄晕了多少Windows程序猿
查看>>
以亲身感受浅谈程序的注释和一个bug的代价(单位:RMB)
查看>>
当printf("-")遇上fork() ---某公司招聘笔试题目
查看>>
谢孟媛老师英语音标发音01(附我备注)
查看>>
谢孟媛老师英语音标发音02(附我备注)
查看>>
如何用C语言判断ip地址是否合法? (用inet_addr有问题)
查看>>
《随遇而安》 孟非
查看>>
如何引用另外一个文件中的串, 顺便说说void print();和(void)print();的区别
查看>>
今天第一次面试别人, 大概聊了近30分钟
查看>>
我经历的那些骗局(要承认, 骗子智商比我们高)
查看>>
C语言一个文件中的函数能直接调用另外一个文件中的静态函数吗? (某公司校园招聘面试试题)
查看>>
有“空洞”的文件的C代码实现
查看>>
简单详解:x^6+4x^4+2x^3+x+1 至少要需要多少次乘法? (某公司实习生招聘笔试试题)
查看>>
int a1=x+y-z; int a2=x-z+y; a1和a2的值一定相等吗? (某公司实习生招聘笔试试题)
查看>>
聊聊这个与代码优化有关的选择题 (某公司实习生招聘笔试试题)
查看>>
Windows环境下利用“共享内存”实现进程间通信的C/C++代码---利用CreateFileMapping和MapViewOfFile
查看>>