Hdu1547 Bubble Shooter 2017-01-20 18:38 44人阅读 评论(0) 收藏
Bubble Shooter
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description

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
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
Sample Input
2 2 2 1
aa
a
3 3 3 3
aaa
ba
bba
3 3 3 1
aaa
ba
bba
3 3 3 3
aaa
Ea
aab
Sample Output
3
8
3
0
分析:其实就是模拟一下就可以了。首先将与起始点直接或间接相连的相同颜色的泡泡标记一下,看总数ans是否大于等于3.
奇数层偶数层分开讨论
之后要分俩种情况讨论了:
1) ans<3 。那么要将之前的标记清除,找出与顶层泡泡直接相连或间接相连的泡泡总数lt,sum-lt就是答案了。这里解决了一个特殊情况,本来以为ans<3的话,直接输出0就可以了,但其实很有可能,即使ans<3,但起始的地图也会有一些泡泡会掉下来。
2)ans>=3,这种情况下,就还是找出与顶层直接相连或间接相连的泡泡总数lt,直接sum-lt。这里就将俩种情况统一起来了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std; int dir1[6][2]= {{-1,0},{-1,-1},{1,0},{1,-1},{0,-1},{0,1}}; //偶
int dir2[6][2]= {{-1,0},{-1,1},{1,0},{1,1},{0,-1},{0,1}}; //奇
char mp[105][105];
int m,n,ans,lt;
char s; bool cheak(int x,int y)
{
if(x<0||x>=m||y<0||y>=n||mp[x][y]=='E')
return 0;
return 1;
} void dfs(int x,int y)
{
int xx,yy;
ans++;
mp[x][y]='E'; if(x%2==0)
{
for(int i=0; i<6; i++)
{
xx=x+dir1[i][0];
yy=y+dir1[i][1];
if(cheak(xx,yy)&&mp[xx][yy]==s)
dfs(xx,yy);
}
}
else
{
for(int i=0; i<6; i++)
{
xx=x+dir2[i][0];
yy=y+dir2[i][1];
if(cheak(xx,yy)&&mp[xx][yy]==s)
dfs(xx,yy);
}
} }
void dfs2(int x,int y)
{
int xx,yy;
lt++;
mp[x][y]='E';
if(x%2==0)
{
for(int i=0; i<6; i++)
{
xx=x+dir1[i][0];
yy=y+dir1[i][1];
if(cheak(xx,yy))
dfs2(xx,yy);
}
}
else
{
for(int i=0; i<6; i++)
{
xx=x+dir2[i][0];
yy=y+dir2[i][1];
if(cheak(xx,yy))
dfs2(xx,yy);
}
}
} int main()
{
int h,w;
while(~scanf("%d%d%d%d",&m,&n,&w,&h))
{
int sum=0;
for(int i=0; i<m; i++)
{
scanf("%s",mp[i]);
for(int j=0;j<strlen(mp[i]);j++)
{
if(mp[i][j]!='E')
sum++;
}
}
for(int i=1; i<m; i+=2)
{
mp[i][n-1]='E';
}
ans=0;
s=mp[w-1][h-1];
dfs(w-1,h-1);
if(ans<3)
printf("0\n");
else
{
lt=0;
for(int i=0; i<n; i++)
{
if(mp[0][i]!='E')
dfs2(0,i);
}
printf("%d\n",sum-lt);
}
}
return 0;
}
Hdu1547 Bubble Shooter 2017-01-20 18:38 44人阅读 评论(0) 收藏的更多相关文章
- Pots 分类: 搜索 POJ 2015-08-09 18:38 3人阅读 评论(0) 收藏
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11885 Accepted: 5025 Special Judge D ...
- c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏
c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...
- 团体程序设计天梯赛L2-003 月饼 2017-03-22 18:17 42人阅读 评论(0) 收藏
L2-003. 月饼 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不 ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
- UI基础:UILabel.UIFont 分类: iOS学习-UI 2015-07-01 19:38 107人阅读 评论(0) 收藏
UILabel:标签 继承自UIView ,在UIView基础上扩充了显示文本的功能.(文本框) UILabel的使用步骤 1.创建控件 UILabel *aLabel=[[UILabel alloc ...
- HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏
Coprime Sequence Time Limit: 2000/1000 MS (Ja ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- hadoop容灾能力测试 分类: A1_HADOOP 2015-03-02 09:38 291人阅读 评论(0) 收藏
实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...
随机推荐
- GridView 绑定数据的常用指定格式。
形式 语法 结果 注释 数字 {0:N2} 12.36 数字 {0:N0} 13 货币 {0:c2} $12.36 货币 {0:c4} $12.3656 货币 "¥{0:N2 ...
- ELF文件和BIN文件
文件的内容:1. BIN文件是 raw binary 文件,这种文件只包含机器码.2. ELF文件除了机器码外,还包含其它额外的信息,如段的加载地址,运行地址,重定位表,符号表等. 所以ELF文件的体 ...
- emacs配置buffer的快捷键
emacsConfig/buffer-setting.el (global-set-key (kbd "<M-left>") 'previous-buffer) (gl ...
- NFS 相关操作指令
1.启动NFS服务器 为了使NFS服务器能正常工作,需要启动portmap和nfs两个服务,并且portmap一定要先于nfs启动. #service portmap start #service n ...
- 图搜索——使用DFS和BFS耗时比较
图测试数据生成代码: #include<bits/stdc++.h> using namespace std; int random(int mod) { return rand() % ...
- Python实现进度条总结
先说一下文本系统的控制符:\r: 将光标移动到当前行的首位而不换行:\n: 将光标移动到下一行,并不移动到首位:\r\n: 将光标移动到下一行首位. 环境:root@ubuntu16: ...
- django rest_framework 框架的使用02
rest_framework 访问频率的限制(节流) 对于用户访问频率的显示,rest_framework 也有自己的类进行约束 先来一个自己的基于它的类的节流类的限制 class VisitCont ...
- maven settings.xml 文件
指定jdk 的版本: <profile> <id>jdk-1.8</id> <activation> <activeByDefault>tr ...
- BDE 升级到FireDAC
BDE Query Replace Str in files by cnpack tools TQueryTFDQuery dmdb->qrypub->Open(sql); fdme ...
- How To Manually Install Oracle Java on Ubuntu
Introduction Java is a programming technology originally developed by Sun Microsystems and later acq ...