Balloons(山东省第一届ACM省赛)
Balloons
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.
They were very interested about this event, and also curious about the image.
Since there are too many balloons, it is very hard for them to compute anything they need. Can you help them?
You can assume that the image is an N*N matrix, while each element can be either balloons or blank.
Suppose element A and element B are both balloons. They are connected if:
i) They are adjacent;
ii) There is a list of element C1, C2,
… , Cn,
while A and C1 are
connected, C1 and C2 are
connected …Cn and B are
connected.
And a connected block means that every pair of elements in the block is connected, while any element in the block is not connected with any element out of the block.
To Saya, element A(xa,ya)and B(xb,yb) is adjacent if |xa-xb| + |ya-yb| ≤ 1
But to Kudo, element A(xa,ya) and
element B (xb,yb) is adjacent if |xa-xb|≤1 and |ya-yb|≤1
They want to know that there’s how many connected blocks with there own definition of adjacent?
输入
The first line of input in each test case contains one integer N (0<N≤100), which represents the size of the
matrix.
Each of the next N lines contains a string whose length is N, represents the elements of the matrix. The string only consists of 0 and 1, while 0 represents a block and
1represents balloons.
The last case is followed by a line containing one zero.
输出
with Saya and Kudo’s definition. Your output format should imitate the sample output. Print a blank line after each test case.
示例输入
5
11001
00100
11111
11010
10010 0
示例输出
Case 1: 3 2
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2152
简单水题:
直接神搜就行了,每一块是气球的都遍历一下,看是否能够成一块新的,然后计数就好了。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
#define MAX 500
#define INF 0x3f3f3f3f
int dir[8][2]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}};
int n;
bool mark[105][105];
char ch[105][105];
int ffind=-1; ///标记是哪个人的
bool dfs(int x,int y){
if(x<0||y<0||x>=n||y>=n) return false;
if(mark[x][y]==1||ch[x][y]=='0') return false; mark[x][y]=1;
int mmax;
ffind==1 ? mmax=4 : mmax=8; for(int i=0;i<mmax;i++)
dfs(x+dir[i][0],y+dir[i][1]);
return true;
} int main (){
int cnt=1;
while(scanf("%d",&n)&&n!=0){ for(int i=0;i<n;i++)
scanf("%s",ch[i]);
int sum1=0,sum2=0; //求解第一个人的
memset(mark,0,sizeof(mark));
ffind=1;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(dfs(i,j)) sum1++;
//求解第二个人用的
memset(mark,0,sizeof(mark));
ffind=2;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(dfs(i,j)) sum2++;
printf("Case %d: %d %d\n\n",cnt++,sum1,sum2);
}
}
Balloons(山东省第一届ACM省赛)的更多相关文章
- Shopping(山东省第一届ACM省赛)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- 山东省第一届ACM省赛
ID PID Title Accepted Submit A 2151 Phone Number 22 74 B 2159 Ivan comes again! 1 17 C 2158 Hello ...
- Emergency(山东省第一届ACM省赛)
Emergency Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...
- 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)
题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...
- 2010山东省第一届ACM程序设计竞赛
休眠了2月了 要振作起来了!!... http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2155 因 ...
- sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)
题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...
- sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散
先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...
- Hello World! 2010年山东省第一届ACM大学生程序设计竞赛
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
Phone Number Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that if a phone number A is anothe ...
随机推荐
- js倒计时跳转链接
(function(){ var loadUrl = 'http://www.cnblogs.com/naokr/',//跳转链接 loadTime = 3000,//跳转时间 reTime = 10 ...
- SpringMVC笔记
Struts1是采用单例模式的,在并发访问中出来资源混乱,于是出现Struts2被设计为多例的解决并发产生的 数据混乱由于Struts2引入了值栈,拦截器,OGNL等,,,是访问速度下降在原生的JSP ...
- 安装 modelsim 10.4
安装教程: http://jingyan.baidu.com/article/da1091fb30d880027849d63a.html 在安装的过程中出现cmd乱(即在输入页面上停留字符),还有吱吱 ...
- linux计划任务
一.单一计划任务 安装at: # yum -y install at 启动: # /etc/init.d/atd start 查看是否运行: # ps aux | grep atd 创建计划 # at ...
- sql语句 decimal(18,0)什么意思
decimal(18,0)18是定点精度,0是小数位数.decimal(a,b)a指定指定小数点左边和右边可以存储的十进制数字的最大个数,最大精度38.b指定小数点右边可以存储的十进制数字的最大个数. ...
- JavaScript 表单验证
长度限制: <script>function test(){if(document.a.b.value.length>50){alert("不能超过50个字符!" ...
- StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks 论文笔记
StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks 本文将利 ...
- 3、C#入门第3课
1.c#中一个解决方案 里面两个程序 怎么一个启动另一个? 我一个解决方案下,有两个工程,我想让A工程在适当时候,启动B工程,比如A中有个按钮,一点,B工程就启动了. System.Diagnosti ...
- BarTender如何将条码下的数字嵌入到条码中
现今社会,在各种包装箱子.书籍.超市商品等东西上面,必不可少的绝对要数条形码或者二维码了.有时候,根据客户的需求或者其他条件限制等原因,我们需要将BarTender 2016条码下的数字嵌入到条码中. ...
- Android开发中经常使用的Content-Type简介
1.application/x-www-form-urlencoded:最常使用的类型(默认也是这种类型),主要用于提交不带文件的post数据. 2.multipart/form-data:需要结合b ...