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 ...
随机推荐
- PARSEC-3.0编译错误
OS: Ubuntu 14.04 LTS (x86_64) ***error 1 OpenSSL 1.0.1e 与 perl5.18 不兼容 POD document had syntax error ...
- Neo4j批量插入(Batch Insertion)
新建一个maven工程,这里不赘述如何新建maven工程. 添加Neo4j jar到你的工程 有两种方式: 上网站官网下载jar包,根据自己的系统下载不同的压缩包,详细过程不描述,请自行搜索其他博客 ...
- python 中md5 和 sha1 加密, md5 + os.urandom 生成全局唯一ID
首先先来介绍一下md5 和 sha1 的概念 MD5 MD5的全称是Message-Digest Algorithm 5(信息-摘要算法).128位长度.目前MD5是一种不可逆算法. 具有很高的安全性 ...
- git提交远程仓库命令
在已有的git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中,从而开始一个新的项目 首先,在本地新建文件夹abc,进入到abc里面,然后git init.这样就在本地初始化了一个g ...
- win10删除或更改需要SYSTEM或Administrators权限的文件夹
有时候我们需要删除一些系统文件夹或者文件,但是却经常会出现如下提示: 遇到这些情况,我们可以采用如下的解决手段. 一.右键单击需要更改或删除的文件夹,选择属性. 二.在弹出的窗口菜单里,选择“安全”选 ...
- Java单例模式(转载)
原文地址:1:http://www.cnblogs.com/hupp/p/4487521; 2:http://cantellow.javaeye.com/blog/838473 先罗列五种单例模式的实 ...
- [原创]cocos2d-x研习录-第三阶 特性之加速度传感器
智能手机的游戏与应用中,也经常会用到加速传感器事件来丰富用户的体验,比如飞翔的企鹅(英文AirPenguin)游戏就是通过加速度传感器来控制角色的移动和跳跃方向.下面学习Cocos2D-x中如何使用加 ...
- 卡尔曼滤波器 Kalman Filter (转载)
在学习卡尔曼滤波器之前,首先看看为什么叫“卡尔曼”.跟其他著名的理论(例如傅立叶变换,泰勒级数等等)一样,卡尔曼也是一个人的名字,而跟他们不同的是,他是个现代人! 卡 尔曼全名Rudolf Emil ...
- ASP.NET(转自wiki)
ASP.NET是由微软在.NET Framework框架中所提供,开发Web应用程序的类库,封装在System.Web.dll文件中,显露出System.Web名字空间,并提供ASP.NET网页处理. ...
- java-装箱/拆箱-字符串转换成基本数据类型
一.理解java中包的含义及种类 java是一个面向对象编程,即一切皆是对象,那么有一个矛盾,从数据上划分知道java中的数据分为基本数据类型和引用数据类型,但是基本数据类型如何是一个对象呢?此时,就 ...