• 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 }
  • 相关阅读:
    TCP 传递信息
    如何在数据源是空的时候,gridview显示表头(万能)
    (orm1)O/R Mapping在实际中用于什么方面最有优势?[转]
    web service 数据传输有什么限制? 为什么?DataTable可以作为web service参数传递么?90
    C#对象的 Xml序列化与反序列化
    题目:当点击按钮时,如何实现两个td的值互换?【js】
    4.如何获取动态生成的SL控件的NAME值(二)
    gridview排序加箭头(二)
    我们没有在一起
    (orm 2) LINQ与ORM
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/8687046.html
Copyright © 2020-2023  润新知