By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

help to solve this question

P: 1
a set of n people(say a,b,c,d) need to assemble as two different teams in
two different rooms (say r1 and r2) to attend discuss two different
topics. participants are given options to pick the room of their interest,
print all the possible ways in which they can conduct the meetings.(while
printing the output, arrange the possiblities in such a way that no. of
people in r1 is in ascending order, and when the no. of people in r1 are
same, the groups are sorted based on their alphabetical order. note that a
set itself is printed as sorted character list. also assume 2<=n<=26)

sample input:
2

output:
- ab
a b
b a
ab -
Sep 15 '06 #1
Share this Question
Share on Google+
3 Replies


risby
P: 30
a set of n people(say a,b,c,d) need to assemble as two different teams in
two different rooms (say r1 and r2) to attend discuss two different
topics. participants are given options to pick the room of their interest,
print all the possible ways in which they can conduct the meetings.(while
printing the output, arrange the possiblities in such a way that no. of
people in r1 is in ascending order, and when the no. of people in r1 are
same, the groups are sorted based on their alphabetical order. note that a
set itself is printed as sorted character list. also assume 2<=n<=26)

sample input:
2

output:
- ab
a b
b a
ab -

I don't understand this at all. What does your sample input mean? Is it that there are just two people? If so then a will go to one room and b to another where they will talk to themselves. What do the space and the dash in your output represent?
Sep 15 '06 #2

100+
P: 293
D_C
Encode the problem using a binary string, and also use recursion.
Suppose n = 6. Then have a six digit binary string, modeled by a six entry boolean array. Then 000000 means all six people are in the first room, 111111 means all six are in the second room. For persons A, C, and D to be in the first room, while B, E, F are in the second, is 010011.

It's 51 lines of code. Of course, I could delete four sets of parenthesis and get it down to 43 lines of code.
Expand|Select|Wrap|Line Numbers
  1. Enter number of people: 4
  2. -       abcd
  3. d       abc
  4. c       abd
  5. cd      ab
  6. b       acd
  7. bd      ac
  8. bc      ad
  9. bcd     a
  10. a       bcd
  11. ad      bc
  12. ac      bd
  13. acd     b
  14. ab      cd
  15. abd     c
  16. abc     d
  17. abcd    -
  18. Press any key to continue . . .
Sep 15 '06 #3

100+
P: 293
D_C
Actually, after thinking about it, recursion is not necessary. It's tail end, so it could be converted to a for loop. Then, you could encode the 2^N possibilities by counting from 0 to (2^N - 1).
Sep 15 '06 #4

Post your reply

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