钱伯斯在城堡的家庭任务 [英] Chambers in castle home assignment

查看:90
本文介绍了钱伯斯在城堡的家庭任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



ima新手,sushant

谁有人可以帮我解决这个问题?


Chambers in a Castle

城堡的平面图表示墙壁的位置。城堡的外部边界始终是一堵不间断的墙。城堡没有门,只有墙壁上的开口从一个房间通向另一个房间。房间是一组房间,通过墙壁的间隙相互连接。问题是:


1.计算城堡中的房间数量。

2.计算最大房间的面积。


为简化问题,城堡的地板分为方形瓷砖。所有墙壁都位于瓷砖边界。房间的面积是根据房间内的瓷砖数量来指定的(不计算周围墙壁占用的瓷砖)。


下图是地板的一个例子计划。每个正方形都是瓷砖。白色瓷砖代表开放空间,而黑色瓷砖代表墙壁。在这座城堡里,有四个房间。最大的房间面积为58.


输入格式

第一行输入将有两个整数M和N,其中0 < M≤500且0 < M≤500.M表示行数,N表示平面图中的列数。


这将是M行输入。这些M行中的每一行将是长度为N的0'和1'的序列,由空格分隔。 0表示开放的瓦片(白色方块),而1表示具有墙壁的瓦片(黑色方块)。城堡的外部边界将始终由不间断的墙壁组成。


输出格式

程序的输出应该是两行,每行包含一个数字。第一行应该是房间数量。第二行应该是最大腔室的大小。

样本输入

这是与上图对应的输入。

15 19

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1

1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1

1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0

1 0 0 0 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1

0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1

1 0 0 0 0 1 1 1 1 1 1 1 0 0 1 0 0 0 1

1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1

1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1

1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1

1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1

1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1

1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1

1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

样品输出

4

58

i知道我们必须使用dfs / bfs ...但是有人可以告诉我如何使用c ++实现n代码吗?

hi
i m a newbie,sushant
could anyone please help me out with this problem??

Chambers in a Castle
The floor plan of a castle indicates where the walls are. The outer boundary of the castle is always an unbroken wall. The castle has no doors, only openings in the walls that lead from one room to another. A chamber is a collection of rooms that are connected to each other by gaps in the walls. The problem is to:

1. Count the number of chambers in the castle.
2. Calculate the area of the largest chamber.

To simplify the problem, the floor of the castle is divided into square tiles. All walls lie at tile boundaries. The area of a chamber is specified in terms of the number of tiles inside the room (without counting the tiles occupied by the surrounding walls).

The figure below is an example of a floor plan. Each square is a tile. White tiles represent open space, while black tiles represent walls. In this castle, there are four chambers. The largest chamber has an area of 58.


Input Format
The first line of input will have two integers M and N, with 0 < M ≤ 500 and 0 < M ≤ 500. M represents the number of rows and N the number of columns in the floor plan.

This will be followed by M lines of input. Each of these M lines will be a sequence of 0''s and 1''s of length N, separated by spaces. A 0 represents an open tile (a white square), while a 1 represents a tile with a wall (a black square). The outer boundary of the castle will always consist of an unbroken wall.

Output Format
The output of your program should be exactly two lines, each line consisting of a single number. The first line should be the number of chambers. The second line should be the size of the largest chamber.
Sample Input
This is the input corresponding to the figure above.
15 19
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1
1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1
1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1
1 0 0 0 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1
1 0 0 0 0 1 1 1 1 1 1 1 0 0 1 0 0 0 1
1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1
1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1
1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1
1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1
1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1
1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1
1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sample Output
4
58

i know that we have to use dfs/bfs...but could anyone plz tell me how to implement n code it using c++??

推荐答案

专家本网站上的s非常乐意帮助您解决问题,但他们无法为您完成任务/计划。首先尝试自己的作业/计划并发布有关您遇到的任何困难或有关您不知道如何实现的特定代码功能的问题。


请阅读< a href =http://www.thescripts.com/forum/faq.php?faq=posting_guidelines\"target =_ blank>发布指南,特别是课程作业发布指南


然后当你准备发布一个新的这个帖子中的问题。


MODERATOR
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don''t know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR


看起来很有趣。回到我们所做的工作。


为什么需要使用dfs / bfs?没有任何有孩子的节点对此有任何意义。


Adrian
Looks interesting though. Get back to us with what work you have done.

Why do you need to use dfs/bfs? There are no nodes with children for this to make any sense.


Adrian



看起来很有趣。回到我们所做的工作。


为什么需要使用dfs / bfs?没有带孩子的节点对此有任何意义。


Adrian
Looks interesting though. Get back to us with what work you have done.

Why do you need to use dfs/bfs? There are no nodes with children for this to make any sense.


Adrian



确实有趣/>

Savage


Intresting indeed

Savage


这篇关于钱伯斯在城堡的家庭任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆