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 }
  • 相关阅读:
    oracle表连接------&gt;排序合并连接(Merge Sort Join)
    内存损坏问题的演示样例及分析
    HTML5 Canvas中9宫格的坑
    hive udaf 用maven打包运行create temporary function 时报错
    Re-installation failed due to different application signatures.
    UVA 6480 Zombie Invasion(模拟退火)
    POJ3436 ACM Computer Factory 【最大流】
    android图像处理系列之三--图片色调饱和度、色相、亮度处理
    android图像处理系列之四--给图片添加边框(上)
    android图像处理系列之五--给图片添加边框(中)
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/8687046.html
Copyright © 2011-2022 走看看