• Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C


    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 ka 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,a,b,如果由一方先出现k点,则清零重新开始比赛,问根据a,b可以知道最多可以比几场

    解法:首先可以猜出,a,b都小于k不符合要求,以及比赛成绩一定是ans=a/k+b/k,但是如果出现k点就清零,所以没有大于k是比分出现,也就是说a或者b大于k,而另一个小于k也是不符合要求的

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     int k,a,b;
     6     cin>>k>>a>>b;
     7     if(a>b)
     8     {
     9         swap(a,b);
    10     }
    11     if(a<k&&b<k)
    12     {
    13         cout<<"-1";
    14         return 0;
    15     }
    16     else if(a/k==0&&b%k)
    17     {
    18         cout<<"-1";
    19         return 0;
    20     }
    21     int ans=(a/k+b/k);
    22     cout<<ans<<endl;
    23     return 0;
    24 }
  • 相关阅读:
    hello world!
    react(一):组件的生命周期
    position和BFC
    继承
    绕不开的this
    js世界这么大,闭包想看看
    js中数组常用方法总结
    Appium混合应用测试
    手机APP兼容性测试
    运行monitor提示需要安装旧JAVA SE 6运行环境
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6399156.html
Copyright © 2020-2023  润新知