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

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

时间:2017-02-14 21:54:44      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:ted   lan   index   eal   win   min   game   span   number   

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,如果由一方先出现k点,则清零重新开始比赛,问根据a,b可以知道最多可以比几场

解法:首先可以猜出,a,b都小于k不符合要求,以及比赛成绩一定是ans=a/k+b/k,但是如果出现k点就清零,所以没有大于k是比分出现,也就是说a或者b大于k,而另一个小于k也是不符合要求的

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int k,a,b;
 6     cin>>k>>a>>b;
 7     if(a>b)
 8     {
 9         swap(a,b);
10     }
11     if(a<k&&b<k)
12     {
13         cout<<"-1";
14         return 0;
15     }
16     else if(a/k==0&&b%k)
17     {
18         cout<<"-1";
19         return 0;
20     }
21     int ans=(a/k+b/k);
22     cout<<ans<<endl;
23     return 0;
24 }

 

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

标签:ted   lan   index   eal   win   min   game   span   number   

原文地址:http://www.cnblogs.com/yinghualuowu/p/6399156.html

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