Address: Http://codeforces.com/contest/765/problem/C
Topic:
C. Table Tennis Game 2Time limit per test2 secondsmemory limit per testMegabytesinputStandard InputOutputStandard Output
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve was 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 has played, or that the situation is impossible.< /c6>
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 have to is at least, points ahead to win a set) have no power within the present problem.
Test instructions: Test instructions good fan, do the problem by enumerating test instructions.
The title says two people are playing, each game has a lot of rounds, each round of winning players can get a point. If someone's score is k in a match, the game ends and a game is re-opened.
Now give the two people a total score, a, B, ask you whether the score is legal (that is, can be in the X-game after the score), if legal, the output of the largest X
Ideas:
Ask for the largest x, greedy selection of each score for 0:k or k:0, the maximum score.
If A%k or b%k is not equal to 0, then the remainder can be consumed in a match.
So the illegal situation is that the remainder is not consumed.
1#include <bits/stdc++.h>2 3 using namespacestd;4 5 #defineMP Make_pair6 #definePB push_back7typedefLong LongLL;8typedef pair<int,int>PII;9 Const Doubleeps=1e-8;Ten Const DoublePi=acos (-1.0); One Const intk=1e5+7; A Const intmod=1e9+7; - - intK,a,b,ans; the - intMainvoid) - { -Cin>>k>>a>>b; +ans=a/k+b/K; - if(a%k!=0&& b/k==0) ans=-1; + if(b%k!=0&& a/k==0) ans=-1; Aprintf"%d\n", ans); at return 0; -}
Codeforces Round #397 by Kaspersky Lab and Barcelona bootcamp (div. 1 + div. 2 combined) c-table Tennis Game 2