Problem:
I am studying C ++ and reading the translation. Everyone said "accelerated C ++", but there is no answer.
I hope you can tell me the answer to this exercise in Chapter 1 !~~ I am grateful if I can copy the answer for me !~~ :
34. Suppose we want to find the median of a value set: and assume that we have read some
It is not clear how many values to read. Proof: we cannot discard any value we have read. Note: 1.
A feasible proof strategy is to first assume that we can discard a value and then find the last read in our collection (that is, not
That part of the value, which requires that the value will make the value exactly the one we lost-
========================================================== ==========================================
Answer:
Because the subsequent values are arbitrary, we can construct a collection of subsequent values after dropping a value so that the discarded value is the value of the entire set.
Proof: After N values have been read, we discard a value of X. It can be calculated that in a read set, there are N1 values greater than X, and N2 values smaller than X, n1 + N2 <n (note that N1 + N2 is not necessarily equal to the N-1 because it may exist in X equal values ).
1) First, consider that there is only one X in the read set.
D = max (N1, N2)-min (N1, N2 ). Then set S = {N1> N2? D (x-1): d (x + 1)}, S is to make X into the entire set of the value of the subsequent value set, so that X can not be discarded.
2) when there are multiple X values, set them to N3. At this time, N1 + N2 + N3 = n, in addition, Y1 is the smallest of all values in the input value greater than X (that is, the bottom confirmation of a subset greater than X). Similarly, Y2 is the upper confirmation of a subset smaller than X.
D = max (N1, N2)-min (N1, N2 ). Set S to {N1> N2? D Y2: D Y1}
Then Y3 = (x-y2)/2, so that the collection of s '= {(n3-1) Y3 }. S and S' are the subsequent numerical sets that make X the median. When the entire set contains N3 X, the value is X. If an X is removed, the value is determined based on the definition of the value at this time:
A) if the entire set is an even number and the smaller value in the middle is the middle value, after removing X, Y3 becomes the middle value. This is incorrect, indicating that X cannot be removed.
B) if the entire set is an even number, take the middle of the large value for the median, you can make y3' = (y1-x)/2 to replace the above Y3, then y3' is the new median. This is incorrect. It also means that X cannot be removed.
In summary, in any case, except any one of the input values, it is possible (that is, there is a set of uninput values) to change the value of the entire set. .