CF 397 C. Table Tennis Game 2
2017-02-15 20:39
453 查看
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 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.
Examples
input
output
input
output
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.
题意:
Misha and Vanya进行了桌球比赛,每场比赛都是由好几场小比赛组成的,每个小比赛赢加1分,输不加分,然后有一个人得了k分就赢得这场比赛,所有比分归零。开始下一场比赛。现在给你三个整数,k(得k分赢一场),a(Misha
所有比赛累积下来的总分),b(Vanya所有比赛累积下来的总分)。问你最多可以组成几场比赛,如果不能组成完整的比赛输出-1,不然输出最大得场数。
注意!!!每组数据都是完整的比赛!!!!!!!(之前没看到这个被人Hack一发,TVT)
题解:
你会发现如果要是完整得比赛的话,如果某个人对k取模有余数的话,对手必需赢过至少一场的话,才能和余数组成一场完整的比赛,不然的话余数无论如何也不能被消耗掉。就是-1呗。其他的话是输出a/k+b/k就可以了。
#include <iostream>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
long long k,a,b;
cin>>k>>a>>b;
long long num1 = a/k;
long long num3 = a%k;
long long num2 = b/k;
long long num4 = b%k;
long long num = num1+num2;
if((num2==0 && num3!=0) || (num1==0 && num4!=0))
cout<<"-1"<<endl;
else
cout<<num<<endl;
return 0;
}
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 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.
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.
题意:
Misha and Vanya进行了桌球比赛,每场比赛都是由好几场小比赛组成的,每个小比赛赢加1分,输不加分,然后有一个人得了k分就赢得这场比赛,所有比分归零。开始下一场比赛。现在给你三个整数,k(得k分赢一场),a(Misha
所有比赛累积下来的总分),b(Vanya所有比赛累积下来的总分)。问你最多可以组成几场比赛,如果不能组成完整的比赛输出-1,不然输出最大得场数。
注意!!!每组数据都是完整的比赛!!!!!!!(之前没看到这个被人Hack一发,TVT)
题解:
你会发现如果要是完整得比赛的话,如果某个人对k取模有余数的话,对手必需赢过至少一场的话,才能和余数组成一场完整的比赛,不然的话余数无论如何也不能被消耗掉。就是-1呗。其他的话是输出a/k+b/k就可以了。
#include <iostream>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
long long k,a,b;
cin>>k>>a>>b;
long long num1 = a/k;
long long num3 = a%k;
long long num2 = b/k;
long long num4 = b%k;
long long num = num1+num2;
if((num2==0 && num3!=0) || (num1==0 && num4!=0))
cout<<"-1"<<endl;
else
cout<<num<<endl;
return 0;
}
相关文章推荐
- Codeforces Round #397(Div. 1 + Div. 2 combined)C. Table Tennis Game 2【贪心】
- Table Tennis Game 2
- C. Table Tennis Game 2
- 【Codeforces 765 C. Table Tennis Game 2】+ 贪心
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C - Table Tennis Game 2
- Table Tennis Game 2
- 【codeforces 765C】Table Tennis Game 2
- Table Tennis Game 2(水题)
- C. Table Tennis Game 2
- C. Table Tennis Game 2 Codeforces Round #397
- Codeforces Round #397 - Problem C - Table Tennis Game 2
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题
- cf D. "Or" Game (前缀+后缀维护单点更新)
- CF 327 A Flipping Game
- cf 154.div2 D. Table with Letters - 2
- CF —— Codeforces Round #428 (Div. 2) B. Game of the Rows
- CF 389A:Fox and Number Game
- CF#338D. GCD Table
- CF - 409 - A. The Great Game(IQ)
- CF:A. Flipping Game