Will you answer this interview question?

Source: Internet
Author: User

This question is excerpted from book C/C ++ programmer Interview Guide

Interview Question 1: Ms's handshake

The Smith and his wife invited four other couples to dinner. It is known that each of them does not shake hands with themselves, shake hands with their spouse, and shake hands with the same person more than once. After the handshake, Smith asked everyone how many times they shook hands.

Q: How many times does Mrs. Smith shake hands?

1. knowledge points involved

· Exclusion

· Analytical Method

2. analyze the problem

To solve this problem, exclusion can be used to exclude irrelevant information first. problems that can be identified should be determined first, so as to narrow down the scope of the unknown as much as possible, so as to facilitate the analysis and resolution of the problem. This way of thinking is very useful in our work and life. According to the given conditions, we can see that:

(1) for a total of 10 people, each person does not shake hands with himself or his/her spouse, but does not shake hands with the same person more than once. Therefore, each person can hold a maximum of 8 hands, at least 0.

(2) Mr. Smith asked the other 9 people to hold their hands several times. The answers were different, so the number of handshakes for each person should be 0 ~ Eight times, one person for each number of times. We can see the number of handshakes of nine people except Mr. Smith, as shown in Figure 12.1.

Suppose I held 8 hands, that is, I held hands with everyone other than my spouse. If I was Mrs. Smith, she held 8 hands, that is, I held a hand with everyone other than Mr. Smith. It can be inferred that the number of handshakes of the other three couples except the MS couple is at least 1, which is in conflict with the number of handshakes of the known. Therefore, this assumption is not true. It can also be inferred that the and I of the handshake 0 times are a couple. For details about the actual handshakes, see Figure 12.2.

Figure 12.1 Number of handshakes between a couple and Mrs. Smith Figure 12.2 Number of handshakes between a couple

(3) According to (2), one of the couples shakes hands with each other, while the other does not. Therefore, couples a can be excluded, that is, assume that couples a did not attend the party, and the number of handshakes of the remaining seven is reduced by 1. At this time, the number of participants is the Smith and the other three couples 8. Except Mr. Smith, the number of handshakes for the other seven is 12.3.

Assume that Mrs. H is Mrs. Smith, and Mrs. Smith shakes hands with each of the other three couples, that is, the number of handshakes of the other six is at least one, but as shown in Figure 12.3, B shook hands 0 times, so the assumption is not true, that is, H is not Mrs. Smith, and can be inferred that B and H are a couple. For details about handshaking after removing a, see Figure 12.4.

Figure 12.3 Number of handshakes between a couple and Mrs. Smith figure 12.4 4. handshakes between a couple

(4) Distribution of handshakes of the other five after removing couple B (that is, assuming that couple B is not attending the party), as shown in Figure 12.5.

Assume that G is Mrs. Smith, and Mrs. Smith shakes hands with each of the other two couples, that is, the number of handshakes of the other four is at least one, but as shown in Figure 12.5, c shakes 0 times, so the assumption is not true, that is, G is not Mrs. Smith, and can be inferred that C and G are a couple. For details about handshaking after removing couples B, refer to figure 12.6.

Figure 12.5 handshakes between two couples and Mrs. Smith figure 12.6 handshakes between three couples

(5) After removing the number of handshakes of the other three (that is, assuming the couple C is not attending the party), 12.7 is shown.

Assume that Mrs. F is Mrs. Smith, and Mrs. Smith shakes hands with each other once. The number of handshakes between the two is at least one, but according to Figure 12.7, d shakes 0 times, so the assumption is not true, that is, F is not Mrs. Smith and can be inferred that D and F are a couple. For details about handshaking after removing couples B, refer to figure 12.6.

Figure 12.7 handshakes between a couple and Mrs. Smith figure 12.8 handshakes between the two couples

The rest is Mrs. Smith. According to Figure 12.1, she held a total of four hands.

3. Answer

Please drag the mouse to the right: Mrs. Smith held her hand four times.

Finding out who is Mrs. Smith is the same as finding out who is not Mrs. Smith. This is the Implementation Technique of exclusion.

Title: Interview Guide for C/C ++ programmers

Prepared by Yang Guoxiang and others

ISBN 978-7-121-10359-9

Publication date: 2010Published in March

Pricing: 49.00 RMB

Publicity

Sort out the technical skills of C/C ++ programmers from the perspective of Enterprise interviews

Measure the test taker's knowledge about C/C ++ programming from the perspective of a Technical Manager.

Description

C and C ++ are the mainstream programming languages in the IT industry and the basic software skills required by many programmers. They are the focus of recruitment and examination in the software development industry. This book introduces the basic concepts of C and C ++ language based on the popular interview questions, this section describes basic concepts of object-oriented programming, including how to implement inheritance, polymorphism, and encapsulation. It also introduces the implementation of sorting algorithms and data structures, including linked lists, stacks, queues, and trees. In addition, this book starts with two chapters to detail the precautions for English and Chinese interviews, FAQs, And the programmer's career planning and other common knowledge of software engineers. The last four chapters detail the current popular intellectual testing questions.

This book provides a detailed description of common technical issues during the C and C ++ interviews, the basic methods of intelligence testing and common questions about mathematical ability, reasoning ability and response ability are also explained in detail. This book is suitable for fresh graduates who are looking for a job, and for old programmers who want to change jobs and have a solid basic knowledge or are not familiar with intelligence testing.

Purchase address: China Interactive publishing network

Recommended similar books:. Net programmer Interview Guide (including one CD) Java programmer Interview Guide

Book details: http://www.broadview.com.cn/10359
For more information, see www.broadview.com.cn.
To get more books and activity information in real time, join the blog reader club!

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.