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 ...
随机推荐
- Sep19_html/css_imooc学习笔记_1
1. <h1></h1>标题,h1-h6从大到小 2. <p></p> 段落 3. <img src=“1.jpg”> 加入图片 4.基本结 ...
- 关于cookie 取不到值的问题
当前我们设置cookie时,跨路径的话,我们会取不到设置的cookie的值 我们要添加上path路径的值,就可以啦.(经过验证) path 的设置方法:path=/; function setcook ...
- mysql常用操作
一.什么是数据库 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库. SQL( Structured Query Language)语言的全称是结构化查询语言.数据库管理系统通过S ...
- Android驱动开发前的准备(三)
Git使用入门 3.1安装Git 3.2查看Git文档 3.3源代码的提交与获取 3.1安装Git # apt-get install git # apt-get install git-doc gi ...
- 《C标准库》——之<string.h>
<string.h>里的字符串操作函数是经常要用到的,因此阅读了源码后自己实现了一些: 拷贝函数 void * Mymemcpy(void * sDst, const void * sSr ...
- 兼容PC手机端字体
各平台的主流字体支持情况 各系统的默认字体和常用字体: 系统 默认西文字体 默认中文字体 其他常用西文字体 其他常用中文字体 Windows 宋体 宋体 Tahoma.Arial.Verdana.Ge ...
- Java中封装、继承和多态
封装: 封装实际上使用方法将类的数据隐藏起来,控制用户对类的修改和访问数据的程度. 适当的封装可以让程式码更容易理解和维护,也加强了程式码的安全性. 访问修饰符有public,private,prot ...
- Object.create() 和 __proto__ 的关系
经测试得出 Ojbect.create() 也就是通过修改 __proto__ 实现的. 例: var Super = { say: function() {console.log('say')} } ...
- BLE 信道
广播信道频点的选择原则上是为了远离诸如WiFi接入点的严重干扰.这些接入点通常选择802.11信道中的3个:信道1.6.11.这几个信道的中心频率分别为2412/2437/2462,宽度大概为20MH ...
- JSBinding+Bridge.NET:Unity游戏热更新方案
老版本链接如下:http://www.cnblogs.com/answerwinner/p/4469021.html 新用户不要再使用老版本了. 新版本 JSBinding 将抛弃 SharpKit ...