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 }
  • 相关阅读:
    Golang 学习之路
    Kubernetes 资源对象之DaemonSet
    Spring Cloud服务注册中心交付至kubernetes
    自动化运维之Ansible入门
    MySQL 高可用之主从复制
    Kubernetes 强大的namespace
    SaltStack RESTful API操作
    Kubernetes 服务自动发现CoreDNS
    2个月……
    一次游玩与这两周的一些感想
  • 原文地址:https://www.cnblogs.com/moomcake/p/8686982.html
Copyright © 2011-2022 走看看