Codeforces Round #335 606A - Magic Spheres

A. Magic Spheres
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet andz orange spheres. Can he get them (possible, in multiple actions)?

Input

The first line of the input contains three integers ab and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal.

The second line of the input contains three integers, xy and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.

Output

If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".

Sample test(s)
input
4 4 0
2 1 2
output
Yes
input
5 6 1
2 7 2
output
No
input
3 3 3
2 2 2
output
Yes
Note

In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.




题目大意是一个魔术师可以将两个相同颜色的球变成另一个不同颜色地球,注意球的数量2->1。

然后现在他有三种球各a, b, c个,问经过上述变换能否最少得到对应的x, y, z个,注意!是最少,不是刚好。


官方题解:

606A - Magic Spheres. Let’s count how many spheres of each type are lacking to the goal. We must do at least that many transformations. Let’s count how many spheres of each type are extra relative to the goal. Each two extra spheres give us an opportunity to do one transformation. So to find out how many transformations can be done from the given type of spheres, one must look how many extra spheres there are, divide this number by 2 and round down. Let’s sum all the opportunities of transformations from each type of spheres and all the lacks. If there are at least that many opportunities of transformations as the lacks, the answer is positive. Otherwise, it’s negative.


意思是算出来a - x, b - y, c - z,然后取其中大于零的除以二向下取余,是这些多出来的球还能贡献给其他颜色的球多少个,然后将除完的数加起来,为能够给其他球贡献的总数,若刚开始减的时候有负数就最后的时候加上这些负的看最后结果是不是大于等于零。

大于等于零的意思是:等于零的时候供需平衡,大于零的时候有盈余,但是题目要求是至少,也就是多出来也无所谓,所以输出Yes

小于零的时候是供不应求,那么肯定达不到至少x, y, z的标准,输出No


#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    int x, y, z;
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d%d%d", &x, &y, &z);
    if ((a -= x) > 0) a /= 2;
    if ((b -= y) > 0) b /= 2;
    if ((c -= z) > 0) c /= 2;
    puts((a + b + c < 0) ? "No" : "Yes");
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值