Home >Backend Development >PHP Tutorial >Logic question: six men and six women
See the picture,
There are six men, referred to as A, B, C, D, E, F. and their mother only in the same village.
Every mother unfortunately lost her husband, but they all remarried. The second husband was one of the five men besides his own son.
Mrs. D said to C’s mother: Due to the second marriage, she (Mrs. D) became Mrs. E’s mother-in-law’s mother-in-law, A became B’s stepfather’s stepfather, and Mrs. F became Mrs. Mrs. C’s daughter-in-law’s daughter-in-law’s daughter-in-law’s daughter-in-law.
Ask who married whom?
I am stupid and can’t figure it out.
You?Old??You?????Program??Drag him out and kick him?
c took a’s mother, a took d’s mother, d took b’s mother, b Take f's mother, f take e's mother, e take c's mother. . .
This actually creates a circle. Anyone among the 12 people can be the elder of whom, it just depends on which side to count from.
c takes a’s mother, a takes d’s mother, and d takes b's mother, b took f's mother, f took e's mother, and e took c's mother. . .
This actually creates a circle. Anyone among the 12 people can be someone’s elder, it just depends on which side is counted
Haha
You? Old?? You???? Program?? Drag it out and kick it?
No, I saw it on the Nomad Star website. I thought about it for a long time and couldn’t figure it out, so I came to ask for advice
The relationship is not an ordinary mess!
The relationship is not an ordinary mess!
That’s right
It’s confusing. . .
What a detour. . .
Feeling dizzy
Such a complicated feeling. . .
Are you sure your question is correct?
I think the question is wrong (I searched and couldn’t find the source)
$dict = array('A', 'B', 'C', 'D', 'E', 'F');//搜索 F太太成了C太太的儿媳妇的儿媳妇的儿媳妇的儿媳妇$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 || 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)); }}//搜索结束,共 24 组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)); //判断,两个条件不能同时满足 if($r[$r['B']] == 'A' && $r[$r[$r['D']]] == 'E') print_r($r); //但分别可以// if($r[$r['B']] == 'A') print_r($r); //A成了B的继父的继父// if($r[$r[$r['D']]] == 'E') print_r($r); //D太太成了E太太的婆婆的婆婆的婆婆}
Are you sure your question is correct?
I think the question is wrong (I searched and couldn’t find the source)
I also saw the question on other websites, I don’t know if it is correct, but the conclusion given on the second floor is applicable. Haha
I did the math, there are two answers
We use capital letters to represent mothers and small letters to represent sons, because the question says that the second husbands were all five other men. One of them, so when connected in the form of son->daughter-in-law->son->daughter-in-law, there should be a chain with 12 points in the end. We use? No. represents unknown.
The first information: Mrs. D is Mrs. E’s mother-in-law’s mother-in-law’s mother-in-law.
The resulting chain D->d->? ->? ->? ->? ->E->e There are 8 points in total, 4 of which are connected to the unknown
The second information: a became b’s stepfather’s stepfather
The resulting chain A->a->? ->? ->B->b There are 6 points in total, 2 are connected to the unknown
The third information: Mrs. F is Mrs. C’s daughter-in-law’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 to the unknown
The next step is to sum these three chains into one (a total of 12 points chain), the third day There happens to be an unknown chain of 6, so the second chain can match it. After matching, the middle two links are 4 points outside the unknown distance, which happens to match the first one, but the position is uncertain, so there are two results, respectively. Is:
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
It meets the conditions,
You? Old?? Your program?? Drag it out and kick it?
The person who asked the question must be a pervert,
Quoting the reply from sibang on the 2nd floor: You?Old??You????Program??Drag him out and kick him?
The person who asked the question must be very perverted,
Absolutely Not a pervert!
Directed graph traversal is a very typical application
What he is talking about is not a technical abnormality, but a physiological/psychological abnormality
Quoting the reply from default7 on the 16th floor: Quoting the reply from sibang on the 2nd floor :You?Old??You???????Program??Drag him out and kick him?
The person who asked the question must be a pervert,
He is definitely not a pervert!
Directed graph traversal is a very typical application
I said I read the question wrong twice, and I wiped it
Method:
C.1.2.3. F
D.1.2.E
A.1.B
Arrange.... Remove D and you cannot marry C’s mother