標籤:deb bytes eps power ros long layer sts imp
地址:http://codeforces.com/contest/765/problem/C
題目:
C. Table Tennis Game 2time limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard 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 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,問你這種得分是否合法(即能否在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