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 }
  • 相关阅读:
    Flex 布局教程:语法篇
    一些不错的滚动条
    SharePoint缓存导致访问慢解决
    针对SharePointFarm场时安装部署OWA的步骤
    【转】必需知道的 SharePoint 权限 Tips
    【转】SharePoint工作流中常用的方法
    通过SPList Definition自定义ListItem打开编辑详细页面
    Jquery 实现Xml文件内容处理
    【转】为 XmlNode.SelectNodes 加上排序功能
    [MSDN]关键字查询语言 (KQL) 语法参考
  • 原文地址:https://www.cnblogs.com/weeping/p/6420941.html
Copyright © 2011-2022 走看看