Table Tennis Game 2(找规律)
Description
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.
Sample Input
11 11 5
1
11 2 3
-1
Hint
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代表的是两人最后的总分数,即每一回合的分数之和。问两个一共进行了多少局比赛,如果不存在这种情况,输出-1。
解题思路:我们知道:1,如果二者的分数都小于k的话连一局比赛都没有比完,是不符合要求的。
2,在一定分数情况下,如果要得到最大的局数,必然是每一局都会出现一人得k分,一人得0分。然后将剩下的分数必然小于k,将其补充到前面的局中,这样能获得最大局数。
3,不过还要考虑一种情况,如果一人分数小于k,而另外一个人分数大于k,要看看是不是k的整数倍,如果是那么没什么问题,说明最后一局胜者完胜;如果不是,最后一局比分将达不到k,是不存在的。
上代码:
#include<stdio.h>
int main()
{
long long k,a,b,t,ans,max,min;
int flag=;
scanf("%lld%lld%lld",&k,&a,&b);
if(a>b)
{
max=a;
min=b;
}
else
{
max=b;
min=a;
}
if(a<k&&b<k)
flag=;
else if(max%k&&min<k)
flag=;
else
{
ans=max/k+min/k;
}
if(flag==)
printf("-1\n");
else
printf("%lld\n",ans);
return ;
}
Table Tennis Game 2(找规律)的更多相关文章
- 1026. Table Tennis (30)
题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...
- PAT 1026 Table Tennis[比较难]
1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元
基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1 5 16 45 121 320 841 2205 5776 151 ...
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
- CF456B Fedya and Maths 找规律
http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
随机推荐
- MySQL数据库的隔离级别之可重复读为什么能够有效防止幻读现象的出现
可重复读隔离级别,不允许存在幻读,该隔离级别之所以能够有效防止幻读现象的出现,是因为可重复读这个隔离级别有用到GAP锁(间隙锁).下面我们以解析SQL语句为切入点,来解释个中原因. 前提条件:①数据库 ...
- Tomcat 或JBOSS java.lang.ArrayIndexOutOfBoundsException: 8192原因及其解决方法
2018-04-02 09:24:55 org.apache.catalina.connector.CoyoteAdapter service 严重: An exception or error oc ...
- js时间与毫秒互相转换
1)日期转换为毫秒 如果格式是:yyyy/mm/dd hh:mm:ss可以直接转换.var oldTime = (new Date("2018/07/09 14:13:11")). ...
- Linux 判断系统任务是否正在运行
#!/bin/bash if ps -ef|grep "php index"|egrep -v grep >/dev/null then >& >> ...
- STM32 HAL库学习系列第6篇---定时器TIM 级联配置
应用情景 使用定时器配置编码器模式,发现STM32只有两个定时器是32位,16位的测量值不够用,发现是可以使用两个16位定时器级联为32位的. 我是在使用编码器计数电机转速时使用,但是最终实现的效果不 ...
- Altium Designer (AD) 中规则的部分讲解
当创建好PCB时,选择 Design - Rules 即可进行规则的设置,也可以直接利用快捷键D-R(多利用快捷键,可以有效的提高设计效率,) 这个是规则的总界面,熟练以后可以直接从这里进行修改,很便 ...
- rcosfir函数的用法
B = rcosfir(R, N_T, RATE, T, FILTER_TYPE) designs and returns a square root raised cosine filter if ...
- ZooKeeper典型使用场景一览
场景类别 典型场景描述(ZK特性,使用方法) 应用中的具体使用 数据发布与订阅 发布与订阅即所谓的配置管理,顾名思义就是将数据发布到zk节点上,供订阅者动态获取数据,实现配置信息的集中式管理和动态更新 ...
- 20155306 实验三 敏捷开发与XP实践
20155306 实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器 ...
- 20145226夏艺华 EXP5 MSF基础应用
实践目标 · 掌握metasploit的基本应用方式. · 具体需要完成 (1)ms08_067; (2)ms11_050: (3)Adobe (4)成功应用任何一个辅助模块. 报告 本次实验一共用到 ...