Table Tennis Game 2

Table Tennis Game 2

The two players played a few rounds of table tennis, each of which won k points first, giving the total score a, b of the two players in a few rounds, seeking a maximum of a few rounds, the impossible combination output -1.

The maximum number of rounds is how many k in a and how many k in b; there are many
possible situations, \ (a, b> = k \) is definitely legal, \ (a, b <k \) is definitely not legal;
consider Mainly one big and one small, and $ min (a, b) <k $ and \ (max (a, b) \) are not multiples of k, $ max (a, b) $ is smaller than k and \ (min (a, b) \) is bigger than k, don't consider it;
if \ (max (a, b) \) is not a multiple of k, that is, \ (min (a, b) \) must have won a round, At least k points;
for example, \ (k = 2, a = 1, b = 3 \) two possible game conditions \ ([a = 1, b = 2] [a = 0, b = 1] \) But the second game did not end;

int main(int argc, const char * argv[]) {
    int k,a,b;
    cin >>k >>a >>b;
    if (min(a,b) < k && max(a,b)%k)
        cout <<-1<<endl;
    else
        cout <<(a/k + b/k)<<endl;
    
    return 0;
}

Guess you like

Origin www.cnblogs.com/i-8023-/p/12710353.html