The question roughly refers to finding out the biggest chip from a gambler. This chip must be the sum of the chips produced by the other three gamblers. the idea is similar to that of half-fold search, because the biggest chip is required to start from n-1.
Sum1 = bet [T]-bet [I];
T starts from N-1 and I starts from 0.
Sum2 = bet [J] + bet [k];
Where J is searched from I + 1, then K (J + 1, n-1) is searched by 2 points, and sum1 = sum2 is output.
Due to the influence of negative chips, T> K> j> I. when wrong answer appears, I began to think about finding that, for example, when-6 1 3 4 K, the serial number of J is larger than that of T. Note that it is necessary to determine whether T is necessary for enumeration! = K & T! = J. although the modification was correct, I found a special case where the test data was not taken into account, for example,-1-2-3-6. that is, T <I <j <K. you need to consider it as a situation, note t! = I.
The Code is as follows:
# Include <set>
# Include <map>
# Include <queue>
# Include <stack>
# Include <math. h>
# Include <string>
# Include <vector>
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <limits. h>
# Include <string. h>
# Include <algorithm>
# Include <functional>
Using namespace STD;
Int bet [1005];
Int find (int I, Int J, int K, int sum ){
Int;
While (I <= J ){
A = (I + J)> 1;
If (K + bet [a] = sum) return;
If (K + bet [a]> sum) J = A-1;
Else I = a + 1;
}
Return 0;
} // Binary Search
Int main (){
Int N;
While (scanf ("% d", & N ){
For (INT I = 0; I <n; I ++)
Scanf ("% d", & bet [I]);
Sort (bet, bet + n );
Int sum, K, Judge = 1;
For (INT I = n-1; I> = 0; I --){
For (Int J = 0; j <= N-3; j ++ ){
If (j = I) continue;
Sum = bet [I]-bet [J];
For (k = J + 1; k <= N-2; k ++ ){
If (k = I) continue;
Int M = find (k + 1, n-1, bet [K], sum );
If (M! = I & M ){
Judge = 0;
Printf ("% d \ n", bet [I]);
Break;
}
}
If (! Judge) break;
}
If (! Judge) break;
}
If (judge ){
Printf ("no solution \ n ");
}
}
Return 0;
}
Zoj1101 solution report