国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Table Tennis Game 2

2019-11-08 18:36:17
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇远县| 东至县| 武城县| 金湖县| 海兴县| 尚义县| 阳城县| 赫章县| 石门县| 樟树市| 九江市| 麻阳| 建始县| 内丘县| 湖北省| 岐山县| 邯郸县| 宁阳县| 库尔勒市| 合作市| 武定县| 高要市| 南充市| 望都县| 罗定市| 赤峰市| 安吉县| 正安县| 桐庐县| 图木舒克市| 奉化市| 万全县| 河池市| 日照市| 宜昌市| 武隆县| 霸州市| 磐石市| 清远市| 永平县| 桂平市|