473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Chambers in castle home assignment

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++??
Jun 5 '07 #1
10 1566
RedSon
5,000 Expert 4TB
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
Jun 5 '07 #2
AdrianH
1,251 Expert 1GB
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
Jun 5 '07 #3
Savage
1,764 Expert 1GB
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

Intresting indeed

Savage
Jun 5 '07 #4
RedSon
5,000 Expert 4TB
Intresting indeed

Savage
Savage,

You are just padding your post count with responses like this :P. Shame on you!

lol
Jun 5 '07 #5
AdrianH
1,251 Expert 1GB
Savage,

You are just padding your post count with responses like this :P. Shame on you!

lol
Shame, shame! ;)


Adrian
Jun 5 '07 #6
Silent1Mezzo
208 100+
Shame, shame! ;)


Adrian
You're doing it too!!
Oh wait...I'm doing it....ah crap.
Jun 5 '07 #7
Savage
1,764 Expert 1GB
We all should be ashamed.

:P

Savage
Jun 5 '07 #8
RedSon
5,000 Expert 4TB
Ashamed, ashamed, ashamed. Say that ten times fast.
Jun 5 '07 #9
RedSon
5,000 Expert 4TB
Okay now thats enough. What have I told you about hijacking a thread....?


Don't do it just to pad your thread count! Have a better reason!
Jun 5 '07 #10
Silent1Mezzo
208 100+
Okay now thats enough. What have I told you about hijacking a thread....?


Don't do it just to pad your thread count! Have a better reason!
Sigh...ok.... I guess we should hav e better reason to post...

It's not like SushantK will come back and check this :P
Jun 5 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
10
by: Andrew Koenig | last post by:
It has been pointed out to me that various C++ books disagree about the relative precedence of ?: and the assignment operators. In order to satisfy myself about the matter once and for all, I...
5
by: CoolPint | last post by:
It seems to me that I cannot assign objects of a class which has a constant data member since the data member cannot be changed once the constructor calls are completed. Is this the way it is meant...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
35
by: nagy | last post by:
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment...
12
by: suprdad25 | last post by:
I was given an assignment to create a MS Access home inventory database that has a minimum of 5 tables. I have 7 tables (Appliances,Vehicles,Movies,Furniture,Games,Electronics, and Rooms) The...
1
by: roundcrisis | last post by:
hi there: Just wondering if there is an interest to meet up in Ireland(in in Dublin) and talk about the castle stack, similarly to alt.net I find that meeting up makes knowledge exchange faster...
4
ssnaik84
by: ssnaik84 | last post by:
Hello, I googled for Castle Windsor usage, but, I got examples of ASP.NET MVC / MonoRail. Can you please explain how to use Castle Windsor with ASP.NET webforms? Thanks in Adv. Swapnil
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.