Links: https://www.nowcoder.com/questionTerminal/365d5722fff640a0b6684391153e58d8?pos=2&orderByHotValue=0&done=0
Source: Cattle-off network
N colors stood in the basement gloves, gloves points left and right, but the number of right hand glove not necessarily the same for each color. Mr. A is now to go out, so he was going to the basement of the players sets. But the dim light he could not distinguish the color of the glove, can only distinguish right-hand man. So he'll get some more gloves, and then select the same pair of gloves the color of right-hand man. The question now is, how many he at least bring gloves (left plus right), in order to ensure the same pair will be able to choose the color of gloves.
Species of a given color number n (1≤n≤13), while two given length n array of left, right, left and right, respectively, represents the number of each color of the glove. Data about the total number of gloves to ensure that not more than 26, and there must be at least a legitimate program.
int FindMinimum ( int n-, Vector < int > left, Vector < int > right) { // Write code here Wallpaper int SUM = 0 ; int leftSum = 0 , rightSum = 0 ; int leftMin = INT_MAX, rightMin = INT_MAX; for ( int = I 0 ; I <n-; I ++ ) { IF (left [I] * right [I] == 0 ) SUM + = (left [I] + right [I]); // calculate the SUM two hands of a only one color is 0, the other hand the number of colors glove sum else { leftSum += left[i]; rightSum += right[i]; leftMin = min(leftMin,left[i]); rightMin = min(rightMin,right[i]); } } return sum + min(leftSum-leftMin+1,rightSum-rightMin+1) + 1; }