Balloons

原题贴上,不给链接了啊。

Description

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?

Input

The input consists of several test cases.
The first line of input in each test case contains one integer N (0<n≤100), which="" represents="" the="" size="" of="" 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.

Output

For each case, print the case number (1, 2 …) and the connected block’s numbers with Saya and Kudo’s definition. Your output format should imitate the sample output. Print a blank line after each test case.

Sample Input

5
11001
00100
11111
11010
100100

Sample Output

Case 1: 3 2
第一届省赛题。比较简单的DFS。就是找连通器的个数。分别找4方向连通跟8方向连通。代码贴上:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace  std;
int f[110][110],n,m;
int mark1[110][110];
int mark2[110][110];
void DFS1(int x,int y){if(x>-1&&y>-1&&x<n&&y<m&&f[x][y]==1&&mark1[x][y]==0){mark1[x][y]=1;DFS1(x-1,y);DFS1(x,y-1);DFS1(x,y+1);DFS1(x+1,y);}
}
void DFS2(int x,int y){if(x>-1&&y>-1&&x<n&&y<m&&f[x][y]==1&&mark2[x][y]==0){mark2[x][y]=1;DFS2(x-1,y-1);DFS2(x-1,y);DFS2(x-1,y+1);DFS2(x,y-1);DFS2(x,y+1);DFS2(x+1,y-1);DFS2(x+1,y);DFS2(x+1,y+1);}
}
int main()
{int kase=1;while(scanf("%d",&n)==1&&n){memset(mark1,0,sizeof(mark1));memset(mark2,0,sizeof(mark2));for(int i=0;i<n;i++){char s[110];cin>>s;m=strlen(s);for(int j=0;j<m;j++)f[i][j]=s[j]-'0';}int sum1=0,sum2=0;for(int i=0;i<n;i++)for(int j=0;j<m;j++){if(f[i][j]==1&&mark1[i][j]==0){sum1++;DFS1(i,j);}if(f[i][j]==1&&mark2[i][j]==0){sum2++;DFS2(i,j);}}printf("Case %d: %d %d\n\n",kase++,sum1,sum2);}return 0;
}

SDNU 1136.Balloons【山东省第一届ACM】【7月20】相关推荐

  1. [2010山东省第一届ACM大学生程序设计竞赛]——Greatest Number

    Greatest Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2157 题 ...

  2. 山东省第一届ACM省赛 H SDUT 2158 Hello World!(穷举)

    Hello World! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We know that Ivan gives Saya ...

  3. 山东省第一届ACM省赛 C SDUT 2153 Clockwise

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  4. 重庆师范大学第一届ACM选拔赛

    下面的题解不会给出题目所以在开头放出比赛链接传送门 本场比赛大部分都是模板题,但是任有记录的必要性 重庆师范大学第一届ACM选拔赛 不一样的食物链 有趣的求和 统计患病人数 皮皮想拜师 爱玩游戏的To ...

  5. 山大华特卧龙学校第一届ACM赛后总结

    山大华特卧龙学校第一届ACM赛后总结_题目 题目B 题目背景 水之积也不厚,则其负大舟也无力.--<逍遥游> 题目描述 为了承载起给定的 个长方体木块,水的深度至少为多少. 输入输出格式 ...

  6. 山大华特卧龙学校第一届ACM赛后总结_题目

    山大华特卧龙学校第一届ACM赛后总结 题目_A 题目描述 孔子学院最近招收了 个学员,并要求他们按照<大学>里说的进行修行:格物,致知,诚意,正心,修身,齐 家,治国,平天下.由于输入限制 ...

  7. 山东省2020年12月计算机考试,12月20日开始报名!山东2020年3月全国计算机等级考试注意事项来咯...

    近日,山东省教育招生考试院发布了<山东省2020年3月全国计算机等级考试报名事项公告>(以下简称<公告>),考生个人网上注册报名时间为2019年12月20日9:00至28日24 ...

  8. 第一届 ACM省赛山东省 Emergency

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo's real name is not Kudo. H ...

  9. “AlphaGo之父”获最新一届ACM计算奖

    近日,2019 年 ACM 计算奖颁出,由于在计算机游戏领域取得突破性进展,"AlphaGo 之父".DeepMind 首席科学家.伦敦大学学院教授 David Silver 获得 ...

最新文章

  1. eclipse实用快捷键
  2. eclipse java代码某一行需要修改注释_看看这些Java代码开发规范吧!你好,我好,大家好!...
  3. 爬虫_python3_requests_2
  4. 关于保存状态的Fragment,setRetainInstance(true)
  5. python安装卡在core inter_python – 如何在我的机器上安装numpy / core ...
  6. 在俱乐部首页看不到的团队成员(更新中...)
  7. [渝粤教育] 厦门理工学院 机械设计 参考 资料
  8. 常用docker管理UI
  9. DOS命令批量删除文件及制作该命令的批处理命令详解
  10. 转载viewstate(一) 太经典的东西 不得不转载保存下来
  11. 永久关闭iptables和selinux
  12. js处理的8种跨域方法
  13. 打印机如何手动正反面Mac设置黑白打印
  14. 陈莉君linux操作系统,Linux操作系统原理与应用(陈莉君)学习笔记.pdf
  15. 怎么看微信撤回的效果?教你看微信已撤回的消息、图片
  16. atcod D - Staircase Sequences
  17. ipad适用计算机专业么,并不适合所有人 iPad Pro买前需认识这几点
  18. command a expects \ followed by text
  19. ZeroLogon(CVE-2020-1472) 漏洞的攻击与防御策略(上)
  20. 3D打印机T3升级corexy  制作过程(二)

热门文章

  1. 用计算机一级考试考的照片要求,2018年全国计算机等级考试报名照片要求
  2. php think app_快来了解下TP6中的超级函数app()!
  3. 微信小程序开发(三)表单提交、PHP后台数据交互
  4. .net Bootstrap实现服务器分页效果
  5. 第二届IEEE 教育与计算机科学国际会议(ETCS2009已全部EI和ISTP检索)
  6. 北京大学曹健——Tensorflow笔记 01
  7. UE4 AI行为树(一)AI追逐玩家
  8. python 一段if语句简单测试bmi指数的代码
  9. 字体图标使用-修改颜色
  10. 百度SEO HTML5汉堡包西餐美食网站模板