Table Tennis Game 2

C. Table Tennis Game 2
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
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.

Examples
input
11 11 5
output
1
input
11 2 3
output
-1
Note
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.

题意:两个人进行乒乓球比赛,比赛分为若干局,每一局分为若干回合,在每一回合中,胜利的人的一分,输的人不得分,若其中有一个人在一局中先得到k分,则这一局结束,两人分数都重置,给你三个数,k,a,b,k代表上面的k,a,b分别代表两人最后的总得分(每一局得分之和),问你两个人最多进行了多少回合比赛,如果不存在这种状况,则输出-1.
解题思路:首先我们要知道,在一定的分数下,如果要得到更多的局数,肯定先让每一局为一个人的k分,一个人的0分,然后剩下的分数补起来就行,特别需要注意的是,最后结束肯定是以一整局结束为准,比如为什么样例2中11,2,3是输出-1,因为两人的得分分别是2,3都小于11,如果最后游戏结束的话,肯定有一个人得到11分,所以这种情况不会出现,所以我们需要特别注意的是,当两个人的分数都小于k时,一定是无解,而两个人的分数都大于k时,答案时a/k + b/k,最复杂的情况是其中一个人的分数小于k,另外一个人的分数大于k,这种情况需要特判一下,那个大于k 的那个人的分数是不是k的整数倍。如果不是,则无解。

#include<bits/stdc++.h>
using namespace std;
long long k,a,b;
int main()
{
    while(~scanf("%I64d%I64d%I64d",&k,&a,&b))
    {
        if(a < k&&b >= k)
        {
            if(b%k != 0)
            {
                printf("-1\n");
            }
            else
            {
                long long x = b/k;
                printf("%I64d\n",x);
            }
        }
        else if(b < k&&a >= k)
        {
            if(a%k != 0)
            {
                printf("-1\n");
            }
            else
            {
                long long x = a/k;
                printf("%I64d\n",x);
            }
        }
        else if(b < k&&a < k)
        {
            printf("-1\n");
        }
        else
        {
            long long x1 = a/k;
            long long x2 = b/k;
            printf("%I64d\n",x1 + x2);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值