Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

本文介绍了一个关于魔法球颜色转换的问题,魔术师需要通过转换相同颜色的球来获得不同颜色的球,以达到特定的目标数量。文章提供了问题背景、输入输出格式及样例,并附带了解决该问题的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
题意:有三种颜色数量分别是a、b、c,然后每两种相同的颜色可以转换成其他的一种颜色,如果颜色的数量分别能大于等于x、y、z,输出yes,否则输出no。

思路:存在某种颜色不足够,用sum的值去保存,等待转换,否则就把多余的记为(p)转换,即sum += p/2。

代码:
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define maxn 100000+50
int main()
{
#ifdef CDZSC_June
    freopen("t.txt","r",stdin);
#endif
    int a[4],b[4],sum = 0;
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    scanf("%d%d%d",&b[0],&b[1],&b[2]);
    for(int i = 0; i<3; i++)
    {
        if((a[i] - b[i]) < 0)
        {
            sum += a[i] - b[i];
        }
        else
        {
            sum += (a[i] - b[i])/2;
        }
    }
    puts(sum >= 0?"Yes":"No");
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值