AtCoder题解——Beginner Contest 170——B - Crane and Turtle

本文解析AtCoderBeginnerContest170B题,即经典的鸡兔同笼问题。通过给出的动物总数X和腿总数Y,判断是否存在合法的鹤和乌龟数量组合。文章提供了解题思路和样例分析。

题目相关

题目链接

AtCoder Beginner Contest 170 B题,https://atcoder.jp/contests/abc170/tasks/abc170_b

Problem Statement

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

Input

Input is given from Standard Input in the following format:

X Y

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

Samples1

Sample Input 1

3 8

Sample Output 1

Yes

Explaination

The statement "there are 3 animals in total in the garden, and they have 8 legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

Samples2

Sample Input 2

2 100

Sample Output 2

No

Explaination

There is no combination of numbers of cranes and turtles in which this statement is correct.

Samples3

Sample Input 3

1 2

Sample Output 2

Yes

Explaination

We also consider the case in which there are only cranes or only turtles.

Constraints

  • 1 ≤ X ≤ 100
  • 1 ≤ Y ≤ 100
  • All values in input are integers.

题解报告

题目翻译

其实就是鸡兔同笼问题啦。

在院子里有鹤和乌龟,每个鹤有两条腿,每个乌龟有四条腿。然后告诉我们 X 个动物,Y 条腿。问这样的组合是否合法。如果合法输出 Yes,如果不合法,输出 No。

样例数据分析

略。

题目分析

可以直接解方程,然后判断合法性。

也可以直接判断合法性。

数据规模分析

100 以内的数据,没有什么难度。

AC 参考代码

略。

P.S.

水一篇文章吧。

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

努力的老周

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

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

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

打赏作者

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

抵扣说明:

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

余额充值