zoukankan      html  css  js  c++  java
  • Table Tennis Game 2(找规律)

    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 ka and b (1 ≤ k ≤ 1090 ≤ a, b ≤ 109a + 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

    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.

    题目意思:两人打乒乓球,比赛若干场,每一场都有若干回合,每一回合胜者得一分,输着不得分,若其中有一个人在一局中先得到k分,这一局比赛结束,二者的分数将会重置。注意!!!a,b代表的是两人最后的总分数,即每一回合的分数之和。问两个一共进行了多少局比赛,如果不存在这种情况,输出-1。

    解题思路:我们知道:1,如果二者的分数都小于k的话连一局比赛都没有比完,是不符合要求的。

                                            2,在一定分数情况下,如果要得到最大的局数,必然是每一局都会出现一人得k分,一人得0分。然后将剩下的分数必然小于k,将其补充到前面的局中,这样能获得最大局数。

                                             3,不过还要考虑一种情况,如果一人分数小于k,而另外一个人分数大于k,要看看是不是k的整数倍,如果是那么没什么问题,说明最后一局胜者完胜;如果不是,最后一局比分将达不到k,是不存在的。

    上代码:

     1 #include<stdio.h>
     2 int main()
     3 {
     4     long long k,a,b,t,ans,max,min;
     5     int flag=1;
     6     scanf("%lld%lld%lld",&k,&a,&b);
     7     if(a>b)
     8         {
     9             max=a;
    10             min=b;
    11         }
    12         else
    13         {
    14             max=b;
    15             min=a;
    16         }
    17      if(a<k&&b<k)
    18             flag=0;
    19      else if(max%k&&min<k)
    20             flag=0;
    21      else
    22      {
    23          ans=max/k+min/k;
    24      }
    25     if(flag==0)
    26         printf("-1
    ");
    27     else
    28         printf("%lld
    ",ans);
    29     return 0;
    30 }
  • 相关阅读:
    问题14:如何拆分含有多种分隔符的字符串
    问题15:如何判断字符串a是否以字符串b开头或结尾
    问题16:如何调整字符串中文本的格式
    第三方支付公司之快钱
    js实现回调功能实例
    oracle查看未提交事务
    Tomcat错误之java.lang.OutOfMemoryError:PermGen space解决方案
    oracle错误之未知的命令开头imp忽略了剩余行解决方案
    修改easyui日期控件只显示年月,并且只能选择年月
    数据库三范式大总结
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/8687046.html
Copyright © 2011-2022 走看看