Logic: What should I do if I have six men and six women?

Source: Internet
Author: User
Logical question: six men and six women see the picture. There are six men, referred to as A, B, C, D, E, F. and their mothers are only in the same village. Every mother, dou', is married again. The second husband is one of the five men except his son. Mrs. D said to her mother C: & nbsp; because of her second marriage, she (Mrs. D) became the mother-in-law of Mrs. E's mother-in-law. A became the logic of B: six men and six women


See the image,
There are six men (A, B, C, D, E, F) in the same village as their mother.
Every mother, dou', is married again. The second husband is one of the five men except his son.

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


Ask who is married to whom? Logical question: 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 generates a loop. if there are 12 elders who can be any one, you can find out where they are.
------ Solution --------------------
Are you sure your question is correct?
I think the question is wrong (the source is not found after searching)
$ Dict = array ('A', 'B', 'C', 'D', 'e', 'F ');

// Search for the daughter-in-law of Mrs F who became Mrs C'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 ));
}
}
// The search is complete. There are 24 groups in total.

Foreach ($ res as $ I =>$ r ){
// Six matching items
$ 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 ));
// Judgment. the two conditions cannot be met at the same time.
If ($ r [$ r ['B'] = 'A' & $ r [$ r [$ r ['D'] = 'e') print_r ($ r );
// But they can
// If ($ r [$ r ['B'] = 'a') print_r ($ r); // A becomes the stepfather of B.
// If ($ r [$ r [$ r ['D'] = 'e') print_r ($ r ); // Mrs. D becomes the mother-in-law of Mrs. E's mother-in-law
}

If the program is wrong, please correct me
------ Solution --------------------
There are two answers to this question.
We use uppercase letters to represent the mother and lowercase letters to represent the son, because the second husband is one of the five other men, therefore, when you connect your son-> daughter-in-law-> son-> daughter-in-law, you should end up with a chain with 12 points. We use? Number indicates unknown.
First Information: Mrs. D is the mother-in-law of Mrs. E's mother-in-law.
D-> d->? ->? ->? ->? -> E-> e: eight points in total, and four links are unknown.
Second Information: a became B's stepfather
The obtained chain A-> a->? ->? -> B-> B, there are 6 points in total, and two links are unknown.
Third information: Mrs. F is the daughter-in-law of Mrs. C's daughter-in-law.
The resulting chain C-> c->? ->? ->? ->? ->? ->? -> F-> f. Six connections at 10 points are unknown.
The next step is to combine these three chains into one (a chain with 12 points in total). On the third day, there was a 6-link unknown, so the second chain can match, the outer distance between the two links is 4 points, which is exactly the same as that of the first link, but the position is not fixed. Therefore, there are two results:
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
Qualified,

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.