Microsoft interview questions

Source: Internet
Author: User

1. In the sorting array, find the number of occurrences of a given number. For example, in [1, 2, 2, 2, 3], 2 appears three times.

The binary search method is used to locate the start and end positions of a given number. In the worst case, the time complexity is O (logn ).
The method is straightforward, but it is still difficult to write the code. If you are interested in xdjm, you can practice it.

2. Reverse Order of a one-way linked list
# Include <stdio. h>
Typedef struct snode {
Char data;
Struct snode * Next;} node;
Node * reserve (node * head ){
Node * P, * q, * R;
P = head;
Q = p-> next;
While (Q! = NULL ){
R = Q-> next;
Q-> next = P;
P = Q;
Q = r ;}
Head-> next = NULL;
Head = P;
Return head;
}

3. Write a regular expression to extract the link address from a string. For example
"The IT interview questions Blog contains many <ahref = http://hi.baidu.com/mianshiti/blog/category/microsoft interview questions> Microsoft interview questions </a>". The extracted address is "Workshop"

In Python:
Import re
P = Re. Compile ('<(? : [^>] *) + Href = ([^>] *) (? : [^>] *) *> ')
Content = "It interview questions Blog contains many <ahref = http://hi.baidu.com/mianshiti/blog/category/microsoft interview questions> Microsoft interview questions </a>"
P. search (content ). the groups () code is sufficient for the given example, but in actual situations, you also need to consider the single quotation marks or double quotation marks on both sides of the link address. href is case-sensitive and the situation will be slightly more complex.

In addition, if the interviewer has no concept of a regular expression, he or she can apply for another question with the interviewer, which generally does not have a big impact.

4. Implement division of two positive integers by programming. Of course, Division operators cannot be used.

Div3 (int A, int B)

{Intresult = 0;

 

While (A> = B)

{

Result ++;

A = A-B;

}

Returnresult;

} // This method is very efficient when a is large and B is very small.

Or:

Int Div (const int X, const int y ){
Int left_num = X;
Int result = 0;
While (left_num> = y ){
Int multi = 1;
While (y * multi <= (left_num> 1 ))

{
Multi = multi <1;
}
Result + = multi;
Left_num-= y * multi;
}
Return result;
}

5. Write a program to find the depth of the Binary Tree

The depth of a tree is equal to max (left subtree depth, right subtree depth) + 1. Recursive Implementation is supported. Assume that the node is defined
Struct Node

{
Node * left;
Node * right;
};
Int getdepth (node * root)

{
If (null = root)

{
Return 0;
}
Int left_depth = getdepth (root-> left );
Int right_depth = getdepth (root-> right );
Return left_depth> right_depth? Left_depth + 1: right_depth + 1;
}

6. Using the balance weight, divide 140 grams of salt into 50 and 90 grams three times?

Method 1:

For the first time: 9 grams can be obtained with a weight at the same time;
Second time: use 7 and 9 grams of salt to name 16 grams of salt. At this time, 25 grams of salt is obtained.
Third time: Use the 25 grams of salt to name the other 25 grams. Therefore, after three times, 50 grams of salt are called and only 90 grams are left.

Method 2:

1. Use the balance to divide 140 grams into 70 and 70 grams.
2. Divide 70 grams into 35 or 35 grams using the balance.
3. Use the balance and weight to divide 35 grams into 20 or 15 portions (20 salt + 2 Weight = 15 salt + 7 weight ).
Obtain 70 + 20 = 90 grams, and 35 + 15 = 50 grams ..

7. Standing at a certain point on the earth, we walked one kilometer south, one kilometer east, and finally one kilometer north, returning to the origin. How many points on the Earth meet such conditions?

On the earth's surface, the North-South direction is along the longitude direction, and the East-West direction is along the latitude direction. If you keep walking north, it will reach the northern point and go south to the southern pole. Therefore, let's take a kilometer to the south, then take a kilometer to the east, and finally take a kilometer to the north to return to the origin. In one case, the starting point is at the northern point, so that we can take a kilometer to the south, then, we can walk any number of kilometers to the east, and finally one kilometer to the north, and finally return to the northern point;
Second, we can think that if we go one kilometer south from point A to point B, then if we go east to a kilometer, we can go back to point A to point B. In this way, we can first find the circle that is only one kilometer around a week near the north and south poles. When this circle falls near the South Pole, we only need to push one kilometer to the north, at this point, the points in the circle can be satisfied. If the circle falls near the Arctic, I will not analyze whether it can push one kilometer north. We can find any number of points near the South Pole to return to this problem.

8. There are three fruit baskets. One contains only an apple, the other contains only an orange, and the other has an apple and an orange. Each fruit basket has a label, but the label is wrong. How do I check a fruit in a fruit basket and correctly mark each fruit basket?

Select one from the fruit basket marked as an apple or orange for inspection.
For oranges, Only oranges are in the basket; only apples are in the fruit basket marked with oranges; and both apples and oranges are in the fruit basket marked with apples.
If it is an apple, There is only an apple in the basket; there is only an orange in the fruit basket marked with an apple; there are both an apple and an orange in the fruit basket marked with an orange.

9. Do not use floating point operations. Draw a circle on the screen (x ** 2 + y ** 2 = r ** 2, where R is a positive integer ).

Considering the symmetry of the circle, we only need to consider the first quadrant.
It is equivalent to finding a curve at the point (0, R) to the point (R, 0). The point on the curve is the closest to R from the center of the circle (0, 0.
We can start from the point (0, R), search right (1, R), bottom (0, R-1), Right Bottom (1, R-1) three points to the center of the distance, select the point closest to R from the center of the circle as the next point. Perform this operation repeatedly until the arrival point (R, 0 ).
Since floating point operations cannot be used, distance comparison can only be performed on the basis of the Distance Square. That is, compare the difference between X ** 2 + y ** 2 and R ** 2.

10. Sort a sentence in reverse order of words. For example, "Hi Baidu com mianshiti" is reversed and then changed to "mianshiti com Baidu Hi ".

You can take the following two steps:
The first step is to change "Hi Baidu commianshiti" to "itihsnim MOC udiab ih" in reverse alphabetical order ". In the second part, the English letters in each word are reversed, and "itihsnim MOC udiab ih" is changed to "mianshiticom Baidu Hi ".

This method can be performed on the original string, and only a few integer variables are required to maintain the pointer, which is less space complexity.

11. Calculate the number of bits in the n-bit integer as 1

Method 1:
Divide the integer by 2. If the remainder is 1, the last digit is 1, and the statistical value is 1.
Perform the preceding operation on the division result until the result is 0.

Method 2:
Considering the Division complexity, you can use the shift operation to replace the division. Perform the bitwise and operation (X & 1) on X and 1. If the result is 1, the last digit is 1, and the statistical value is 1. Change X to the right (x> 1) and repeat the above process until the result is 0 after the shift.

Method 3:
If you need to count a lot of numbers and the memory is large enough, you can consider recording the number of BITs corresponding to each number as 1, so that each computation is only one search operation.

Method 4:

Int n = 0; while (X)
{X = x & (X-1 );
N ++ ;}
Return N; // This method is the most efficient, and each time it is clear that one of X is 1.

12. quickly obtain 7 times of an integer

The multiplication is relatively slow, so the fast method is to convert the multiplication to addition, subtraction, and shift operations.
This integer can be first shifted to three places (x 8) and then subtracted from the original value (x <3)-X.

13. judge whether a number is a power of 2 N times

Return (X & (x-1) = 0) the number of bits in the integer of n bit is a special case of 1. Note that 1 is the power of 0 of any number.

14. Each of the three triangle vertices has an ant, which moves toward another vertex and the target is random (possibly any of the other two vertices ). What is the probability that three ants will not collide?

If the ant crawls clockwise, It is counted as 0, and the anti-clockwise crawls are counted as 1. The three ants may be in the 000,001,..., 110,111 state, and the probability of each State is equal. In these eight States, only 111 and 1/4 can avoid collision, so the probability of an ant not collision is.

Some questions are extended:
1. If a triangle is changed to a square with Four ants, what is the probability of no collision? (1/8)

 

15. A given array with the length of N is given. The value range of each element is 1 to n. Checks whether there are repeated numbers in the array. (The original array does not have to be retained)

Method 1.
Sort the Array (fast, heap) and compare whether the adjacent elements are the same.
The time complexity is O (nlogn), and the space complexity is O (1 ).

Method 2.
Use the bitmap method.
A char array with a length of N/8. Each bit indicates whether the corresponding number has exists. Traverse the array and use bitmap to check whether the number appears.
The time complexity is O (n), and the space complexity is O (n ).

Method 3.
Traverse the array. Assume that the number at position I is J, then switch J to the position where the subscript is J. Until all numbers appear in their corresponding subscript, or conflict occurs.
The time complexity is O (n), and the space complexity is O (1 ).

16. A piece of rectangular cake with a small rectangular hollow (angle arbitrary ). How can I use a straight knife to cut the cake into two equal portions?

The rectangle can be divided by any straight line in the center of the rectangle, so the straight line connecting the center of the two rectangles can be equal to this cake.

17. A list without sorting, such as list = {A, L, X, B, E, F, F, E, A, G, H, B, m }, remove the duplicate items and keep the original order. After removing the duplicate items from the linked list, newlist = {A, L, X, B, E, F, G, H, m} is displayed }, write an efficient algorithm (time is more important than space ).

Create a hash_map. The key is the node content that has been traversed in the linked list. It is blank at the beginning.
Start from scratch to traverse nodes in a table:
-If the node content already exists in hash_map, delete the node and continue traversing backward;
-If the node content is not in hash_map, the node is retained, the node content is added to hash_map, And the traversal continues.

18. James had a bridge and it was dark when crossing the bridge, so there must be lights. It takes 1 second for James to bridge the bridge, 3 seconds for James's younger brother, 6 seconds for James's father, 8 seconds for James's mother, and 12 seconds for James's grandfather. Each time a bridge can be crossed by a maximum of two people, the speed of the bridge depends on the shortest speed of the bridge, and the light will go off 30 seconds after it is ignited. Q: How does the James family bridge the bridge? ()

James and his younger brother used to come back and use 4 s;
Mom and grandpa used to come back and use 15 s;
James and his younger brother used to come back and use 4 s;
James and his father used 6 s;
A total of 29 s.

19. Compile a program to calculate the sum of quality numbers, for example, F (7) = 2 + 3 + 5 + 7 + 11 + 13 + 17 = 58.

Method 1:
Perform the following operations on the incremental integer n starting from 2:
Remove n from the number in [2, n-1] sequentially. If the remainder is 0, n is not a prime number. If none of the remainder is 0, n is a prime number, perform addition.

The space complexity is O (1), and the time complexity is O (n ^ 2), where N is the maximum qualitative value to be found (the value corresponding to the example is 17 ).

Method 2:
A prime number sequence can be maintained. To determine whether a number is a prime number, you only need to determine whether it can be divisible by a smaller prime number than yourself. Perform the following operations on the incremental integer n starting from 2:
Remove n from [2, n-1] Prime Numbers (, which is null at the beginning). If the remainder is 0, n is not a prime number; if none of the remainder is 0, N indicates that N is a prime number. Add this prime number to the prime number sequence and add it.

The space complexity is O (M), and the time complexity is O (Mn), where M is the number of prime numbers (in this example, the value is 7 ), n is the maximum numeric value to be found (in this example, the value is 17 ).

Method 3:
You can also use addition instead of division. Apply for a large enough space. Each bit corresponds to an integer and starts to initialize all bits to 0. For known prime numbers (only 2 at the beginning), change the bits corresponding to all multiples of this prime number to 1, so the bit with the smallest value of 0 corresponds to a prime number. The multiples of the new prime numbers are also marked. In this way, the prime number and can be obtained by accumulating the prime number sequence.

The space complexity is O (n), and the time responsibility is O (n), where N is the maximum qualitative value to be found (the value corresponding to the example is 17 ).

The density function of the nth prime number can be used to estimate the size of the prime number, and then conservatively increase the coefficient.

20. Give an algorithm for shuffling and store the cards in an integer array.

Assume that the number of 54 cards in the array card [0-53] corresponds to 54 cards, starting from the first card (I = 0) until the last card (I = 52 ), each time a number R is generated between [I, 53], the numbers in card [I] and card [R] are exchanged.

21. Two unidirectional linked lists may have public nodes. Determine whether there are public nodes and find their first public node.

If two one-way linked lists have public nodes, the two linked lists form a Y-structure and the last node is the same. We can traverse two linked lists from the beginning and find the pointer of the last node, which is set to P_a and P_ B. Record the length of len_a and len_ B of the two linked lists at the same time (assuming len_a> = len_ B ).

If P_a = P_ B, the two linked lists have public nodes; otherwise, no. If a public node exists, the distance between the first public node and the Start Node is len_a-start_a = len_ B-start_ B. Therefore, the distance between the first common node and the Start Node is len_a-len_ B, 0. We start from the two nodes until we find the first public node.

22. How do I find circular links in the linked list?

From the beginning of the linked list, two pointers, A and B, start the time series table at the same time. Each time pointer A moves one step forward, pointer B moves two steps forward. If, after N steps are moved, pointers a and B point to the same node, a circular linked list exists in the linked list.

Of course, you can also store the node address during the traversal process and compare the address to determine whether there is a circular linked list. However, this algorithm uses more memory.
If the examiner is abnormal, you can copy the Linked List directly. If no cyclic linked list is tested before replication, sorry, you can only deduct points.

23. A 500-litre car is driven from A to B, 1000 kilometers away. It is known that the fuel consumption of a car is 1 litre per kilometer, and there is an infinite amount of oil at, there is no oil in any other place, but the car can store oil in any place for transshipment. How much oil is needed from A to B?

There are several prerequisites for minimum fuel consumption: 1. The fuel tank is empty when the car reaches the terminal. 2. There is no oil left in every shard on the road.

Now draw a number axis, representing the path from the start point to the end point. On this number axis, take M points as X (1), X (2 ),..., X (m ). X (I) indicates the distance from the I-th point to the end point. Point 1 is the start point, and point M is the end point. Therefore, x (1) = 0, x (m) = 1000. Set the car tank capacity to A. The question shows that a = 500. If S (I) is set, it indicates the minimum volume of oil to be stored in I. Obviously S (m) = 0, and what we need is S (0 ). Set N (I) to the number of round trips required from the first I-1 point to the second I point (note that one trip represents a round trip ). Well, the above are some symbols to be defined,

The derivation process starts as follows:

When the oil is moved from the I-1 point to the I point, the most savings is that the fuel tank should be filled with oil when starting from the I-1 point, and then when I point put the oil back to the I-1 point, the fuel tank is empty, at this time

The efficiency is the highest. So there are: S (I) = a-[X (I)-X (I-1)] + {A-2 * [X (I)-X (I-1)]} * n (I ).

In the above formula A-[X (I)-X (I-1)] is the last remaining oil from the I-1 point to the I point tank; {A-2 * [X (I) -X (I-1)]} * n (I) indicates the total oil that is stored at point I during N (I) round trips. Merge the previous simplification to get the formula (1 ):

S (I) = [n (I) + 1] * a-[2 * n (I) + 1] * [X (I)-X (I-1)] ----- (1)

And because the oil to the point I is equal to the oil under the point I-1 minus the total loss from the I-1 point to the point I, the total loss from the I-1 point to the I point is [2 * n (I) + 1] * [X (I)-X (I-1)], so there is the following formula:

S (I) = S (I-1)-[2 * n (I) + 1] * [X (I)-X (I-1)].

The formula (2-1) can be obtained by bringing the formula (1) to the upper formula ):

S (I-1) = [n (I) + 1] * A ----- (2-1)

Likewise (2-2)

S (I) = [n (I + 1) + 1] * A ----- (2-2)

 

Use (2-1) minus (2-2) to get the formula (3 ):

S (I-1)-S (I) = [n (I)-N (I + 1)] * A ----- (3)

Because S (I-1)-S (I) represents the total loss from the I-1 point to the I point, and a is a fixed value, so it is known from the (3) formula, to minimize the total loss, the minimum N (I)-N (I + 1) is required.

Because S (I-1)-S (I) must be> 0, so n (I)-N (I + 1)> 0, and N [I] is an integer, so there is Min ([n (I)-N (I + 1)]) = 1. So formula (4 ):

N (I)-N (I + 1) = 1 => N (I) = N (I + 1) + 1 ----- (4)

After formula (4) is substituted into formula (2-2), formula (5) is obtained ):

S (I) = N (I) * A ----- (5)

After formula (5) is substituted into formula (1) and simplified, formula (6) can be obtained ):

X (I)-X (I-1) = A/[2 * n (I) + 1] ----- (6)

X (I)-X (I-1) represents the distance between two adjacent points, so obviously to reach the end point, there must be:

 

N (m) = 0, that is, round-trip is not required from the last vertex to the end. Then the formula (4) has: n (S-1) = 1, n (m-2) = 2 ,..., N (I) = M-I. We will roll back from the end point to the start point, and then there will be:

 

So M = 8. However, when m is 8, the sum obtained is about 1010.9 greater than 1000. Therefore, we cannot calculate S (0) directly by formula (5), but s (1) first) = m-1) * A = (8-1) * 500 = 3500 litre. That is to say, 3500 liters of oil should be stored in the first shard. Then we calculate the loss from 0th to 1st. From the previous calculation, we can get x (1) = 1000-(500 + 500/3 + 500/5 + 500/7 + 500/9 + 500/11 + 500/13) ≈ 22.433 meters.

So the total loss from 0th to 1st points can be calculated by the previous formula [2 * n (I) + 1] * [X (I)-X (I-1: [2 * n (1) + 1] * (22.433-0) = (2*7 + 1) * 22.433 = 336.495

Therefore, the total fuel consumption is about 3500 + 336.495 = 3836.495 liters.

 

 

 

The question can be attributed to an = 500/(2n + 1) n =, 2, 3 ...... when is the sum of Sn greater than or equal to 1000, and the solution N> 6 when n = 6, S6 = 977.57

Therefore, the distance between the first vertex and the starting position is 1000-977.57 = 22.43 kilometers.

So before the first transit, a total of 22.43*(2*7 + 1) = 336.50 liters of oil consumed
After that, each transit consumes 500 liters of oil
Therefore, the total fuel consumption is 500 + 336.50 = 3836.50 liters.

24 known (1) Each aircraft has only one fuel tank; (2) the aircraft can refuel each other (note that there is no fuel dispenser); (3) A box of oil allows an airplane to fly around the Earth in half a lap. How many planes are required to take at least one plane round the earth and return to the airport when it starts? (All planes take off from the same airport and must return to the airport safely. stopover is not allowed. There is no airport in the middle)

Five flights. Specific Method of flight: ABC 3 take off at the same time, 1/8 places, C fill AB with oil, c Return, 1/4 places, B fill a with oil, B Return, A reaches 1/2 places, c. Take off from the airport to the other direction. For example, C is equal to a of the empty fuel tank. For B, take off from the airport. For AC to 3/4, the remaining fuel is equal to B, three planes return at the same time. So it was five flights.

 

 

25 if you have an infinite amount of water, a 3-litre lift, a 5-litre lift, the two are not in the same shape, how can you accurately claim 4 liters of water?

This question is equivalent to: known two numbers 3 and 5, available operators + and-, requires that one end of + and-must be 3 or 5, and the intermediate result cannot be greater than 5. List an expression with the result equal to 4.
Answer 1 4 = 5-(3-(5-3)
Answer 2 4 = 3-(5-3) + 3

26 a fork in the road leads to honest and lie country. There are two people who know that one is honest and the other is lying. Honest countries always tell the truth, and lie countries always lie. Now you are going to lie to the country, but you don't know which path to take. You need to ask these two people. What should I ask?

Ask "How do you go in your country ?" They all point to honest countries. (If the correct answer has only one fixed side, the answer given by two people must be different. You can only ask questions that have different correct answers for everyone, for example, "Where is your country ?" Or "where is his country ". In response to two problems, honest people will give honest and lying directions, while honest people will also give honest and lying directions .)

If you want to ask only one person a question, you can only ask this question: "Do you think he will tell me how to go honestly ?" It is equivalent to two people talking about the truth and telling a lie. No matter who asks this sentence, the opposite direction will be obtained.

27. If you ask a worker to work for you for seven days, the return is a golden stripe, Which is evenly divided into seven connected segments. You must give them a golden stripe at the end of each day. If you are only allowed to break the gold bars twice, how do you pay your workers?

Cut the gold bars into 1/7, 2/7, 4/7.
The first day to 1/2, the second day to 2/7 and get 1/7, the third day to 1/7, the fourth day to 4/7 and get 1/7 and 2/7, the fifth day to 1/7, the sixth day to 2/7 and get 1/7, the Seventh Day is 1/7. The key to this question is to realize that it is possible for workers to change to zero (of course, there must be zero for workers ). After realizing this problem, the specific cut-down method was successfully completed.

28. A cup. If it is broken on the nth floor, it will be broken on any floor higher than n. If it is not broken on the nth floor, it will be broken on any floor lower than M, I will give you two of these cups so that you can test them on a 100-storey floor. You need to use the least number of tests to find the floor that happens to make the cup broken.

Since the number of throws in the first step (determining the critical segment) is inevitable, we will reduce the number of throws in the second step (determining the critical layer) as the number of throws in the first step increases. The number of throws in the first step increases at a time, which reduces the number of throws in the second step at a time. Assume that the number of layers to be dropped for the first time is F, which is converted into a mathematical model. F + (F-1) +... + 2 + 1> = 99, that is, F (F + 1)/2> = 99, and the solution result is 14. DP [M, N] is the minimum number of times that N cups on the m layer must be tested. DP [M, N] = min {max {DP [I, n-1], DP [M-I, n-1]} + 1}

29. It takes an hour to burn an uneven rope from the beginning to the end. Now there are several ropes of the same material. How can I use the rope burning method to time the rope for 1 hour and 15 minutes?Analyze the operations we can perform on time through the rope: 1) 1/2 of the time can be obtained by igniting the two ends of the rope. 2) When one rope is burned, the other rope is ignited, and time can be added. 3) ignition the two ropes at the same time to obtain the time difference between the burning ends of the two ropes, that is, to subtract the time. That is to say, by burning the rope, we can divide the time by 2, add points, and subtract operations. To get one hour and 15 minutes, we can perform the following operations (in minutes ):
60/2 + (60-60/2)/2 + 60/2 (corresponding to the explanation in the above answer)
(60-60/2)/2 + 60
60/2/2 + 60

30. You have a bucket of jelly, including yellow, green, and Red. Close your eyes and capture two of the same colors. You can determine if you have two joos of the same color after capturing them?According to the drawer principle, four

31. To draw 10 straight lines at nine points, must each line have at least three points?

32. 7. How many times does the hour, minute, and second hands of the clock overlap in the 24 hours of a day? What is the time? How did you calculate it?23 times, because the minute-hand has to turn around 24 times, the hour-hand can turn around 1, and the interval between the minute-hand and the hour-hand coincidence is obviously> 1 hour, they have 23 chances of overlap, there is a coincidence opportunity for the second point in each duplicate, so it is 23 times.

33. How to plant four trees so that the distance between any two trees is equal?Plant trees on the Earth's surface and build a positive triangle that is connected to the Earth.

34. One train leaves Beijing at a rate of 15 kilometers per hour and goes straight to Guangzhou. Another train departs from Guangzhou to Beijing at a rate of 20 kilometers per hour. If a bird starts at a speed of 30 kilometers per hour and two trains start at the same time, and departs from Beijing, it returns to the opposite direction after encountering another car, in this way, the two trains will fly back and forth until they meet each other. How long does the bird fly?Determine the time when a train encounters. Multiply the bird's speed by the time, which is the distance from the bird's flight.

35. You have four cans containing pills, each of which has a certain weight. The contaminated pills have a weight of + 1. How can I determine which jar of medicine is contaminated once?Take 1, 2, 3, and 4 pills in each of the four cans to determine the amount of pills that are heavier than normal.

36. the three switches outside the door correspond to three indoor lights respectively. The line is good. When the switch is outside the door, the indoor lights cannot be seen. Now, only one entry is allowed. Are you sure the relationship between the switch and the lamp?Three switches are respectively: Turn off, turn on, turn on for 10 minutes, then enter the room, dark and cooling switch 1 control lights, light switch 2 control lights, dark and hot light for Switch 3 Control

37. Why is RMB only the nominal value of 1, 2, 5, and 10?Because 1.2.5.10 can be used to add or subtract the smallest number, for example, 1 + 2 = 3 2 + 2 = 4.1 + 5 = 6.2 + 5 = 7.10-2 = 8.10-1 = 9'38. There are two jars, each with 50 red and blue balls, and a random jar is selected to randomly select a ball. How can we set the maximum selection rate for the red ball? Returns the exact probability of a red ball.One can has one red ball, and the other can has 49 red balls and 50 basketball balls.
39. Give you two 6-sided sketches, which can be engraved with any 0-9 number on each of them, requiring that they be used to spell out the date value of any year012345 0126 (9) 78

40. the professor selects two numbers from 2 to 9, tells students a their sum, tells students B their product, and asks them to take turns to guess the two: "I can't guess," B said. "I can't guess." A said. "I guess." B said. "I guess ."

3 and 4 (strictly proven)
Set the numbers to N1, N2, N1> = n2. The numbers heard by a are n = N1 + N2. The numbers heard by B are m = N1 * N2, which proves that n1 = 3, n2 = 4 is the unique solution

Proof: To prove that the preceding proposition is true, prove n = 7 1) necessity: I) n> 5 is obvious, because n <4 is not possible, N = 4 or n = 5 A. No answer is available.

Ii) n> 6 because if n = 6, although Jia does not know (not sure whether 2 + 4 or 3 + 3) however, no matter whether it is or, it cannot be said that you do not know (M = 8 or M = 9 if B does not know it is unreasonable)

Iii) n <8 because if n> = 8, N can be divided into N = 4 + X and n = 6 + (X-2 ), then M can be 4x or 6 (X-2) and 4x = 6 (X-2) the necessary condition is X = 6 that n = 10, in this way, N can be divided into 8 + 2, so when n> = 8, n can at least be divided into the sum of two different composite numbers. When B does not know, A has no reason to immediately know.

The above proves the necessity 2) Adequacy when n = 7, N can be decomposed into 2 + 5 or 3 + 4

Obviously, 2 + 5 does not match the meaning of the question, and it is easy to determine that 3 + 4 matches the meaning of the question, M = 12, after the certificate is completed, n = 7 m = 12 n1 = 3 n2 = 4 is the only solution.

41. There are 100 households in a residential area. Each household has a dog. Every evening, people walk the dog in the same place. Some of these dogs are known to be ill. For some reason, the dog owner cannot determine whether his or her dog is ill, but can tell whether other dogs are ill, the household was asked to execute these sick dogs and not to identify the dogs of others as ill dogs (that is, they could only judge themselves). After seven days, all the sick dogs were executed, how many sick dogs are there? Why?

7 (mathematical induction proof)
1) if there is only one sick dog, because the sick dog owner cannot see any other sick dogs, he must know that his dog is a sick dog (provided that there must be a sick dog ), so he will execute the sick dog on the first day.
2) if K dogs are set up, they will be executed on the K-day. If k + 1 dogs exist, the master of the dog will only see K healthy dogs, on the K Day, no one killed the sick dog. The master of the sick dog knew that his dog was a sick dog on the K + 1 day, so the sick dog was executed on the K + 1 day.
3) from 1) 2) If n dogs are ill, they must be executed on the nth day.

42. There are 100 rooms in the prison, and each room has a prisoner. One day, the prison director said, There is a lamp outside your room, and you can control the lamp when the wind goes off ). Every day, only one person can come out to let the wind go, and the wind is random. If, within a limited time, one of you can say to me, "I can assure you that everyone has spared the wind for at least one time ." I will release you! Ask the prisoners what strategies should they adopt before they can be released by the prison director? If this policy is adopted, how long can they be released?

The rules for setting a person as the speaker (or the first person to let the wind go) are as follows:
1. When the reporter turned on the light, and the number of times the light was turned on
2. When others first turn the light off when the light is turned on
3. When the reporter turned on the light 100th times, he reported to the prison director and asked the Director to release the light ......

According to the probability, they can be released after about 30 years (10000 days ).

Note: they are all found online. It is actually not very useful to practice your mind. I have met msra and asked if the probability of the above questions is not none, but very small; I would like to ask about the basic knowledge and flexible application of data structures, the project experience on my resume, and my understanding of the positions I apply.

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.