Logic question: Six men and six women, how to deal with

Source: Internet
Author: User
Logic question: Six men and six women


See picture,
There are six men, referred to as a,b,c,d,e,f. And their mother only in the same village.
Every mother Dou ' unfortunate widowed, but all married again. The second husband was one of the five men except his own son.

Mrs. D said to C's mother: Because of the second marriage, she (Mrs. D) became Mrs. E's mother-in-law's mother-in-law, a became a B's stepfather's stepfather, and Mrs. F became Mrs. C's daughter-in-Iaw's daughter-in-Iaw's daughter-in-IAW.


Ask who married who? Logic Questions six men Six women


------Solution--------------------
C took a mom, a took D mom, D took b mom, B took f mom, F took e mom, E took c mom ...
This actually produced a ring, 12 people who can be the elders of who, just see how from which side forget
------Solution--------------------
Are you sure that your question is correct?
I think the problem is wrong (search for a bit and not find the source)
$dict = Array (' A ', ' B ', ' C ', ' D ', ' E ', ' F ');

Search Mrs. F became Mrs. C's daughter-in-law's daughter-in-law.
$st = Array (
Array (' F ' = = ' A '),
Array (' F ' = = ' B '),
Array (' F ' = = ' C '),
Array (' F ' = = ' D '),
Array (' F ' = ' E '),
);

while ($rs = Array_shift ($st)) {
$len = count ($rs);
$k = End ($RS);
if (Isset ($rs [$k])) continue;
foreach ($dict as $v) {
if ($k = = $v
------Solution--------------------
In_array ($v, $rs)) continue;
if ($len = = = 4 && $v = = ' C ') $res [] = Array_merge ($rs, array ($k + = $v));
else $st [] = Array_merge ($rs, array ($k = = $v));
}
}
Search ended, total 24 groups

foreach ($res as $i = = $r) {
6 +
$k = current (Array_diff ($dict, Array_keys ($r)));
$v = current (Array_diff ($dict, $r));
if ($k = = $v) continue;
$r = Array_merge ($r, array ($k = = $v));
Judging, two conditions cannot be met simultaneously
if ($r [$r [' B ']] = = ' A ' && $r [$r [$r [' D ']]] = = ' E ') print_r ($r);
But you can
if ($r [$r [' B ']] = = = ' A ') print_r ($r); A stepfather who became a B.
if ($r [$r [$r [' D ']]] = = ' E ') print_r ($r); Mrs. D became the mother-in-law of Mrs. E's mother-in-law.
}

If the procedure is wrong, please correct me.
------Solution--------------------
I've counted, there are two answers.
We use uppercase to represent the mother, lowercase for the son, because the title of the second husband is one of the other five men, so when the son-in-law son-in-law, such as daughter-in-law such a way to connect down, and finally should be a chain of 12 points. We use? The number indicates unknown.
The first message: Mrs. D is Mrs E's mother-in-law's mother-in-law.
The obtained chain D->d->? ->? ->? ->? ->e->e a total of 8 points, 4 attached to the unknown
The second message: A step-dad's stepfather who became a B.
The obtained chain A->a->? ->? ->b->b a total of 6 points, 2 attached to the unknown
The third message: Mrs. F is Mrs. C's daughter-in-law's daughter-in-law's daughter-in-law
The obtained chain C->c->? ->? ->? ->? ->?->?->f->f a total of 10 points 6 connected unknown
Next is to put the three chain and as a (a total of 12 points of the chain), the third day just a 6 even unknown, so the second chain can be met, in accordance with the middle of two connected unknown distance outside is 4 points, just as well as the first match, but the position is variable, so there are two kinds of results, respectively:
1:c->c->a->a->d->d->b->b->f->f->e->e
2:d->d->c->c->a->a->e->e->b->b->f->f
Meet the criteria,
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.