AtCoder题解 —— AtCoder Beginner Contest 188 —— A - Three-Point Shot

题目相关

题目链接

AtCoder Beginner Contest 188 A 题,https://atcoder.jp/contests/abc188/tasks/abc188_a

Problem Statement

A basketball game is being played, and the score is now X-Y. Here, it is guaranteed that X ≠ Y X≠Y X=Y.
Can the team which is behind turn the tables with a successful three-point goal?
In other words, if the team which is behind earns three points, will its score become strictly greater than that of the other team?

Input

Input is given from Standard Input in the following format:

X Y

Output

If the team which is behind can turn the tables with a successful three-point goal, print Yes; otherwise, print No.

Sample 1

Sample Input 1

3 5

Sample Output 1

Yes

Explaination

The team with 3 3 3 points is behind.
After a successful 3 3 3-point goal, it will have 6 6 6 points, which is greater than that of the other team - 5 5 5.

Sample 2

Sample Input 2

16 2

Sample Output 2

No

Explaination

The gap is too much. The team which is behind cannot overtake the other by getting 3 3 3 points.

Sample 3

Sample Input 3

12 15

Sample Output 3

No

Explaination

A 3 3 3-point goal will tie the score but not turn the tables.

Constraints

  • 0 ≤ X ≤ 100 0≤X≤100 0X100
  • 0 ≤ Y ≤ 100 0≤Y≤100 0Y100
  • X ≠ Y X≠Y X=Y
  • X X X and Y Y Y are integers.

题解报告

题目翻译

有两个队进行篮球比赛,对应的比分是 X X X - Y Y Y,保证 X ≠ Y X \neq Y X=Y。问落后的队伍能否通过一次 3 3 3 分球获得胜利。

题目分析

一个简单的数学题。
直接的思路就是判断 X X X Y Y Y 的大小,假设 Y Y Y 较小,如果 Y + 3 > X Y+3 > X Y+3>X,那么可以获胜,否则不能获胜。
经过观察,我们发现只需要两队比分差再 3 3 3 分以内,落后方才能通过一个 3 3 3 分球获胜。也就是说当满足 ∣ X − Y ∣ < 3 \lvert X-Y \lvert < 3 XY<3 的时候,才可能出现这样的情况。

数据范围分析

ABC 的 A 题,数据范围都很小。根据题目可知,int 足够。

AC 代码

//https://atcoder.jp/contests/abc188/tasks/abc188_a
//A - Three-Point Shot
#include <bits/stdc++.h>

using namespace std;

//如果提交到OJ,不要定义 __LOCAL
//#define __LOCAL

int main() {
#ifndef __LOCAL
    //这部分代码需要提交到OJ,本地调试不使用
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    int x,y;
    cin>>x>>y;

    if (abs(x-y)<3) {
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }

#ifdef __LOCAL
    //这部分代码不需要提交到OJ,本地调试使用
    system("pause");
#endif
    return 0;
}

在这里插入图片描述

时间复杂度

O(1)。

空间复杂度

O(1)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
AtCoder Beginner Contest 134 是一场 AtCoder 的入门级比赛,以下是每道的简要题解: A - Dodecagon 目描述:已知一个正十二边形的边长,求它的面积。 解思路:正十二边形的内角为 $150^\circ$,因此可以将正十二边形拆为 12 个等腰三角形,通过三角形面积公式计算面积即可。 B - Golden Apple 目描述:有 $N$ 个苹果和 $D$ 个盘子,每个盘子最多可以装下 $2D+1$ 个苹果,求最少需要多少个盘子才能装下所有的苹果。 解思路:每个盘子最多可以装下 $2D+1$ 个苹果,因此可以将苹果平均配到每个盘子中,可以得到最少需要 $\lceil \frac{N}{2D+1} \rceil$ 个盘子。 C - Exception Handling 目描述:给定一个长度为 $N$ 的整数序列 $a$,求除了第 $i$ 个数以外的最大值。 解思路:可以使用两个变量 $m_1$ 和 $m_2$ 别记录最大值和次大值。遍历整个序列,当当前数不是第 $i$ 个数时,更新最大值和次大值。因此,最后的结果应该是 $m_1$ 或 $m_2$ 中较小的一个。 D - Preparing Boxes 目描述:有 $N$ 个盒子和 $M$ 个物品,第 $i$ 个盒子可以放入 $a_i$ 个物品,每个物品只能放在一个盒子中。现在需要将所有的物品放入盒子中,每次操作可以将一个盒子内的物品全部取出并配到其他盒子中,求最少需要多少次操作才能完成任务。 解思路:首先可以计算出所有盒子中物品的总数 $S$,然后判断是否存在一个盒子的物品数量大于 $\lceil \frac{S}{2} \rceil$,如果存在,则无法完成任务。否则,可以用贪心的思想,每次从物品数量最多的盒子中取出一个物品,放入物品数量最少的盒子中。因为每次操作都会使得物品数量最多的盒子的物品数量减少,而物品数量最少的盒子的物品数量不变或增加,因此这种贪心策略可以保证最少需要的操作次数最小。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的老周

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值