Table Tennis Game 2

本文介绍了一种关于乒乓球比赛得分的算法,通过分析比赛得分情况,确定比赛中可能进行的最大回合数。具体而言,该算法考虑了不同的得分组合,并提供了一个有效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

Input

11 11 5

Output

1

Input

11 2 3

Output

-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.

 

 

第一段翻译

Misha和Vanya打了几场乒乓球比赛。每一组由几个发球,每个发球都由一个队员赢球,他得到一分而失败者什么也得不到。一旦其中一名球员得分准确的k分,分数就会重置,新的开始。

在所有的比赛中,米沙的得分总计得分,而Vanya得分为b分。给定这些信息,确定它们可以播放的集合的最大数量,或者情况是不可能的。

 

 

理解错了题意,就WA了 n 多次

意思就是:两个人进行乒乓球比赛,比赛分为若干局,每一局分为若干回合,在每一回合中,胜利的人的一分,输的人不得分,若其中有一个人在一局中先得到k分,则这一局结束,两人分数都重置,给你三个数,k,a,b,k代表上面的k,a,b分别代表两人最后的总得分(每一局得分之和),问你两个人最多进行了多少回合比赛,如果不存在这种状况,则输出-1.

分了 三种情况

1.两人得分都小于 k 则输出  -1

2.两人中一人得分 小于 k,两一个人 大于 k 但是并不能整除 ,则输出 -1

3.两人中 都大于 k 并且都能整除  则 sets=a/k+b/k;  例如 k=11,a=11,b=22 则 sets=11/11+22/11=3

 

 

第一种和第二种 可以合并成为一种情况讨论

代码如下:

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int k,a,b,n;
    while(scanf("%d%d%d",&k,&a,&b)!=EOF){
        if((a<k&&b%k!=0)||(b<k&&a%k!=0))
            printf("-1\n");
        else{ n=a/k+b/k;
            printf("%d\n",n);
        }
    }
}

我以为是在 a b 中找个最大的数来 除 k 然后就wa。

 

 

统计下文中单词出现的个数存入字典,统计出现字数最多的三个单词和最少三个单词。删除原文中出现次数第二多的单词,其他单词保持顺序不变,先试试删除单词后的文章。 Sports help everyone to keep healthy, happy, and efficient. So 1 pay special attention to games,especially table-tennis. Table tennis is my favorite game. I play it almost every day Table-tennis is an ideal game for us because it brings the whole body into action. It strengthens our muscles, expands our lungs, promotes the circulation of the blood, and causes a healthy action of the skin. Besides, it is very amusing and does not cost us much money. Table-tennis is very moderate; it is not so rough as football. It is an indoor game and can be played even on rainy days. Thus, it is my favorite kind of exercise. One morning a fox sees a cock.He think,"This is my breakfast. He comes up to the cock and says,"I know you can sing very well.Can you sing for me? The cock is glad.He closes his eyes and begins to sing.The fox sees that and catches him in his mouth and carries him away. The people in the field see the fox.They cry,"Look, look!The fox is carrying the cock away. The cock says to the fox,"Mr Fox,do you understand?The people say you are carrying their cock away.Tell them it is yours.Not theirs. The fox opens his mouth and says,"The cock is mine, not yours.Just then the cock runs away from the fox and flies into the tree.多加注释,要流程图
最新发布
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值