Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.
Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.
Note that the game consisted of several complete sets.
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
11 11 5
1
11 2 3
-1
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
题意:
Misha and Vanya进行了桌球比赛,每场比赛都是由好几场小比赛组成的,每个小比赛赢加1分,输不加分,然后有一个人得了k分就赢得这场比赛,所有比分归零。开始下一场比赛。现在给你三个整数,k(得k分赢一场),a(Misha 所有比赛累积下来的总分),b(Vanya所有比赛累积下来的总分)。问你最多可以组成几场比赛,如果不能组成完整的比赛输出-1,不然输出最大得场数。
注意!!!每组数据都是完整的比赛!!!!!!!(之前没看到这个被人Hack一发,TVT)
题解:
你会发现如果要是完整得比赛的话,如果某个人对k取模有余数的话,对手必需赢过至少一场的话,才能和余数组成一场完整的比赛,不然的话余数无论如何也不能被消耗掉。就是-1呗。其他的话是输出a/k+b/k就可以了。
#include <iostream>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
long long k,a,b;
cin>>k>>a>>b;
long long num1 = a/k;
long long num3 = a%k;
long long num2 = b/k;
long long num4 = b%k;
long long num = num1+num2;
if((num2==0 && num3!=0) || (num1==0 && num4!=0))
cout<<"-1"<<endl;
else
cout<<num<<endl;
return 0;
}