C. Table Tennis Game 2 time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard 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.
題意:兩個人進行乒乓球比賽,比賽分為若干局,每一局分為若干回合,在每一回合中,勝利的人的一分,輸的人不得分,若其中有一個人在一局中先得到k分,則這一局結束,兩人分數都重置,給你三個數,k,a,b,k代表上面的k,a,b分別代表兩人最后的總得分(每一局得分之和),問你兩個人最多進行了多少回合比賽,如果不存在這種狀況,則輸出-1. 解題思路:首先我們要知道,在一定的分數下,如果要得到更多的局數,肯定先讓每一局為一個人的k分,一個人的0分,然后剩下的分數補起來就行,特別需要注意的是,最后結束肯定是以一整局結束為準,比如為什么樣例2中11,2,3是輸出-1,因為兩人的得分分別是2,3都小于11,如果最后游戲結束的話,肯定有一個人得到11分,所以這種情況不會出現,所以我們需要特別注意的是,當兩個人的分數都小于k時,一定是無解,而兩個人的分數都大于k時,答案時a/k + b/k,最復雜的情況是其中一個人的分數小于k,另外一個人的分數大于k,這種情況需要特判一下,那個大于k 的那個人的分數是不是k的整數倍。如果不是,則無解。
#include<bits/stdc++.h>using namespace std;long long k,a,b;int main(){ while(~scanf("%I64d%I64d%I64d",&k,&a,&b)) { if(a < k&&b >= k) { if(b%k != 0) { printf("-1/n"); } else { long long x = b/k; printf("%I64d/n",x); } } else if(b < k&&a >= k) { if(a%k != 0) { printf("-1/n"); } else { long long x = a/k; printf("%I64d/n",x); } } else if(b < k&&a < k) { printf("-1/n"); } else { long long x1 = a/k; long long x2 = b/k; printf("%I64d/n",x1 + x2); } } return 0;}新聞熱點
疑難解答