Description
两人进行若干场比赛,一场比赛分若干轮,一场开始前两人分数均为 0 0 ,每轮胜者得一分,败者不得分,一方率先得到分则该场比赛结束,给出 n n 场比赛之后两人的总得分和 b b ,问该总得分是否合法,如果合法输出比赛场数的最大值
Input
三个整数 k,a,b(1≤k≤109,0≤a,b≤109,a+b>0) k , a , b ( 1 ≤ k ≤ 10 9 , 0 ≤ a , b ≤ 10 9 , a + b > 0 )
Output
如果该比分合法则输出最大比赛场数 n n ,否则输出
Sample Input
11 11 5
Sample Output
1
Solution
因为进行了完整的 n n 场比赛,故必有一方得分为的整数倍,此时比赛场数最大为 ⌊ak⌋+⌊bk⌋ ⌊ a k ⌋ + ⌊ b k ⌋ ,否则无解,
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
int main()
{
int k,a,b;
while(~scanf("%d%d%d",&k,&a,&b))
printf("%d\n",(a%k&&b/k==0||b%k&&a/k==0)?-1:(a/k+b/k));
return 0;
}