標籤: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 k, a 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.
Examplesinput
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