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只在 ...
随机推荐
- linux 下 ifcfg-eth0 配置/CentOS_minimal安装和开发环境部署
CentOS_minimal安装和开发环境部署:http://www.th7.cn/system/lin/201305/39002.shtml 网络接口配置文件 [root@localhost ~]# ...
- /etc/sysctl.conf参数解释(转)
来自<深入理解Nginx模块开发与架构解析> P9 #表示进程(例如一个worker进程)可能同时打开的最大句柄数,直接限制最大并发连接数fs.file max = 999999 #1代表 ...
- OpenSSL编写SSL,TLS程序***
一.简介 SSL(Secure Socket Layer)是netscape公司提出的主要用于web的安全通信标准,分为2.0版和3.0版.TLS(Transport Layer Security)是 ...
- 转转转!!Spring MVC控制器用@ResponseBody声明返回json数据报406的问题
本打算今天早点下班,结果下午测试调试程序发现一个问题纠结到晚上才解决,现在写一篇博客来总结下. 是这样的,本人在Spring mvc控制层用到了@ResponseBody标注,以便返回的数据为json ...
- 除去a标签target="_blank"的方法
用Jquery:$(function(){$("div>a").attr("target","_blank");});先查找页面上的d ...
- 八、jdk工具之JvisualVM、JvisualVM之二--Java程序性能分析工具Java VisualVM
目录 一.jdk工具之jps(JVM Process Status Tools)命令使用 二.jdk命令之javah命令(C Header and Stub File Generator) 三.jdk ...
- HDU 1710 Binary Tree Traversals(树的建立,前序中序后序)
Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- JQuery input file 上传图片
表单元素file设置隐藏,通过其他元素打开: .imgfile为input file $(".ul").click(function () {return $(".img ...
- EMF与GEF
基于Eclipse的编程架构 类似的场景大家基本都见过: JBPM--流程插件 Mule---ESB插件
- Linux 性能分析的前 60 秒
编译自:http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html作者: Brendan Gregg转载自:h ...