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的时候暴力打表找规律,打表可以用二进制枚举
随机推荐
- 【css】 如何修改select的样式
select { /*清除select默认样式*/ appearance:none; -moz-appearance:none; -webkit-appearance:none; -ms-appear ...
- http 协议状态码
1xx 信息类状态码 100 - Continue 初始的请求已经接受,客户应当继续发送请求的其余部分.(HTTP 1.1新) 101 - Switching Protocols 服务器将遵从客户 ...
- MySQL学习【第七篇索引管理及执行计划】
一.索引介绍 1.什么是索引? 索引由如字典,目的就是为了更快寻找到要找的内容. 令搜索查询的数据更有目的性,从而提高数据检索的能力 2.索引类型介绍 1.BTREE: B+树索引 2.HASH: H ...
- Linux之CentOS7.5安装及克隆
官网下载地址:https://www.centos.org/,点击Get CentOS Now,点击DVD ISO,选择本国资源Actual Country ,一般选择列表中第一行就可以下载. 这里我 ...
- attr 和 prop的区别
attr 返回的是字符串 prop 返回的是布尔值
- Shell 变量简介
1. 概述 概述 知识点又稀又碎, 面试一问就流泪 简单介绍下 shell 下的变量及其基本操作 2. 环境 操作系统 CentOS Linux release 7.5 用户 root 用户 约定 使 ...
- HDFS(0.20.2)运营中急救方案
这段时间折腾的都是hadoop和lucene,总结了hadoop在运营过程中出现问题时的解决方案,请大家指教! HDFS(0.20.2)运营中急救方案 1 Namenode 挂掉( ...
- 20155206 2016-2017-2 《Java程序设计》第十周学习总结
20155206 2016-2017-2 <Java程序设计>第十周学习总结. 教材学习内容总结 教材学习内容总结 Java的网络编程 •网络编程是指编写运行在多个设备(计算机)的程序,这 ...
- 20155215 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20155215 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑 ...
- 20155328 2016-2017-2 《Java程序设计》第四周学习总结
学号 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 继承:避免多各类间重复定义行为,extends关键字表示继承后再扩充原本没有的行为.如果没有使用exte ...