zoukankan      html  css  js  c++  java
  • Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题

    C. Table Tennis Game 2

    题目连接:

    http://codeforces.com/contest/765/problem/C

    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

    11 11 5

    Sample Output

    1

    Hint

    题意

    两个人在打乒乓球,每一个set是这样的:每一局会有一个人胜利,胜利者得1分,失败者得0分,如果有人得了k分,那么这个set结束。

    现在这两个人打了若干个set,A总共拿了a分,B总共拿了b分,问你可不可能。

    题解:

    答案比较显然是a/k+b/k。

    但是注意这个坑点,2 3 1这个数据。

    把这个数据过了就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    long long k,a,b;
    int main()
    {
        cin>>k>>a>>b;
        if(a<b)swap(a,b);
        if(a<k&&b<k){
            cout<<"-1"<<endl;
            return 0;
        }
        long long ans = a/k + b/k;
        if(a%k&&b/k==0){
            cout<<"-1"<<endl;
            return 0;
        }
        if(a/k==0&&b%k==0){
            cout<<"-1"<<endl;
            return 0;
        }
        cout<<a/k+b/k<<endl;
    }
  • 相关阅读:
    Linux进程关系
    ambari 卸载脚本
    CentOS-7.2安装Ambari-2.6.1
    MYSQL57密码策略修改
    CentOS7 离线安装MySQL
    centos 安装mysql Package: akonadi-mysql-1.9.2-4.el7.x86_64 (@anaconda)
    mysql 数据备份
    spring-boot-starter-thymeleaf对没有结束符的HTML5标签解析出错
    ssh: scp命令
    python:os.path
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6401444.html
Copyright © 2011-2022 走看看