Gloves _ cattle off network

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.

Test sample:
  4,[0,7,1,6],[1,5,0,6]
  Returns: 10 (explained: handed glove can take two, take the right glove 8)
 
Ideas: Select a hand glove, this glove hand to meet :( total - minimum + 1), because (total - minimum + 1) satisfies the hand of each color have got, let's use the other hand any one glove to meet the meaning of the questions.
Special case: if the hand is selected (A) the number of a certain color glove is 0, on the other hand (B) should take 1 + B [A glove as the sum of the color 0] glove, due to the in B ensure that got a certain non-zero color in a glove.
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;
}

 

 

Guess you like

Origin www.cnblogs.com/dabai56/p/10982841.html