zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    long类型的数据转化为时间
    取到数组中对应位置的文字,并且转成大写
    无key值的json数组解析
    mongo-2ds索引对超过半球范围的适用性测试
    mongoDB-Cannot change the size of a document in a capped collection:
    springboot
    左中右布局的五种实现方式
    spring boot 常见的配置问题
    移动端H5拍照代码实现及外网部署
    JAVA数据库操作回滚小结
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6399156.html
Copyright © 2011-2022 走看看