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

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

    题目:

    C. Table Tennis Game 2
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    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 ≤ 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.

    Examples
    input
    11 11 5
    output
    1
    input
    11 2 3
    output
    -1
    Note

    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,问你这种得分是否合法(即能否在x场比赛后出现这种得分),如果合法,输出最大的x

    思路:

      要求最大的x,贪心的选取每场比分为0:k或k:0时,比分最大。

      如果a%k或b%k不等于0,那么可以用某一场比赛消耗掉这些余数。

      所以不合法的情况就是这些余数消耗不掉。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define MP make_pair
     6 #define PB push_back
     7 typedef long long LL;
     8 typedef pair<int,int> PII;
     9 const double eps=1e-8;
    10 const double pi=acos(-1.0);
    11 const int K=1e5+7;
    12 const int mod=1e9+7;
    13 
    14 int k,a,b,ans;
    15 
    16 int main(void)
    17 {
    18     cin>>k>>a>>b;
    19     ans=a/k+b/k;
    20     if(a%k!=0 && b/k==0)    ans=-1;
    21     if(b%k!=0 && a/k==0)    ans=-1;
    22     printf("%d
    ",ans);
    23     return 0;
    24 }
  • 相关阅读:
    1951: [Sdoi2010]古代猪文
    BZOJ 1911: [Apio2010]特别行动队[斜率优化dp]
    BZOJ 2038: [2009国家集训队]小Z的袜子(hose)&&莫队算法
    gdb命令整理
    1833: [ZJOI2010]count 数字计数
    1227: [SDOI2009]虔诚的墓主人
    P3197 [HNOI2008]越狱
    3505: [Cqoi2014]数三角形
    P3414 SAC#1
    3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛
  • 原文地址:https://www.cnblogs.com/weeping/p/6420941.html
Copyright © 2011-2022 走看看