Description
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.
Input
The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).
Output
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
Sample Input
11 11 5
1
11 2 3
-1
Sample Output
Hint
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.
题解:两个人玩游戏,最终两个人的得分为a,b,当两个人的得分为k时比分清零并开下一场,问最多经过几场比赛?注意:a,b为最终比分。其实其中一方分数只要不到k,另一方就一定赢这场比赛。
代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
int k,a,b;
cin>>k>>a>>b;
int s1=a%k,s2=b%k,s3=a/k,s4=b/k;
if(s1!=0&&s4==0||s2!=0&&s3==0)//如果一方得分小于k,另一方还不是k的整数倍,输出-1。
cout<<"-1"<<endl;
else
cout<<s3+s4<<endl;
return 0;
}