码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-02-20 19:52:10      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:deb   bytes   eps   power   ros   long   layer   sts   imp   

地址: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 }

 

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

标签:deb   bytes   eps   power   ros   long   layer   sts   imp   

原文地址:http://www.cnblogs.com/weeping/p/6420941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!