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)?
The first line of the input contains three integers a, b 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, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
4 4 0 2 1 2
Yes
5 6 1 2 7 2
No
3 3 3 2 2 2
Yes
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;
}