Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C - Table Tennis Game 2

地址: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\n",ans);
23     return 0;
24 }
时间: 2024-10-21 01:59:52

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C - Table Tennis Game 2的相关文章

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

A. Neverending competitions time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (f

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)

传送门:http://codeforces.com/contest/765 A题:给你家的名字,以及n张机票的起点和终点,Jinotega一开始在家,你要根据这些机票的起点和终点判断Jinotega最后是不是在家.直接记录起点和终点家出现的次数,如果相等说明Jinotega在家,否则不在家. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include &

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B

Description Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate th

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding

地址:http://codeforces.com/contest/765/problem/E 题目: E. Tree Folding time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Vanya wants to minimize a tree. He can perform the following operation mu

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) D. Artsem and Saunders

地址:http://codeforces.com/contest/765/problem/D 题目: D. Artsem and Saunders time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Artsem has a friend Saunders from University of Chicago. Saunders

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C

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 r

Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A

Description There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artse

Codeforces Round #397 (Div. 2)

A - Neverending competitions 没有任何价值..... 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int INF = 0x3f3f3f3f; 4 const int maxn = 100 + 5; 5 typedef long long LL; 6 typedef pair<int, int>pii; 7 8 char home[5]; 9 int main() 10 { 11 in

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/