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 k, a 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.

    Sample Input

     题解:每一轮系列赛若要完成胜出的一方需要达到k分。此题分为两种情况:(1)a<k&&b<k;(2)c=max(a,b),c%k!=0&&min(a,b)<k输出-1,其他情况输出a/k+b/k;
    (Input
    11 11 5
    Output
    1
     1 #include <iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 #include<stack>
     6 #include<queue>
     7 #include<deque>
     8 using namespace std;
     9 int main()
    10 {
    11     int i,j,n,ans=0,t,k,ans1=0,m,b,a;
    12     scanf("%d%d%d",&a,&b,&n);
    13     m=n>b?n:b;
    14     k=n>b?b:n;
    15     ans=m/a;
    16     ans1=k/a;
    17     if((ans==0&&ans1==0))
    18         printf("-1
    ");
    19     else
    20     {
    21 
    22             if(m%a!=0&&k<a)
    23                 printf("-1
    ");
    24             else
    25                printf("%d
    ",ans+ans1);
    26     }
    27         return 0;
    28 }
  • 相关阅读:
    洛谷P1120信息奥赛一本通1442 小木棍
    洛谷P1378 油滴扩展
    洛谷P1156 垃圾陷阱
    mybatis-Plus 实践篇之逆向工程
    Interceptor的使用及探究
    mysql,oracle,sqlServer 元数据查询
    navicat premium15免费版安装说明(附工具)
    打印日志你真的会吗?
    线程基础知识-必知必会
    空间复杂度&时间复杂度
  • 原文地址:https://www.cnblogs.com/moomcake/p/8686982.html
Copyright © 2011-2022 走看看