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

本文介绍了一个基于贪心算法解决的魔术球问题。该问题描述了一位魔法师如何通过转换相同颜色的球来获得所需数量的不同颜色球的过程。文章提供了完整的代码实现,并解释了背后的逻辑。

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

A. Magic Spheres

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.codeforces.com/contest/606/problem/A

Description

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 Input

4 4 0
2 1 2

Sample Output

Yes

HINT

 

题意

有三个物体

你现在分别有a,b,c个

你希望每种物品至少x,y,z个

然后两种相同的物品可以换成一个其他的物品

问你是否能够满足

题解:

贪心,首先,你拥有的超过需要的你才会变

然后你把这个数量记录下来,和你还差多少比一下就好了

代码:

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int a[3];
int b[3];
int main()
{
    for(int i=0;i<3;i++)
        cin>>a[i];
    for(int i=0;i<3;i++)
        cin>>b[i];
    for(int i=0;i<3;i++)
        a[i]=a[i]-b[i];
    int flag1 = 0,flag2 = 0;
    for(int i=0;i<3;i++)
    {
        if(a[i]>0)
            flag1+=a[i]/2;
        else
            flag2+=a[i];
    }
    flag2 = -flag2;
    if(flag1>=flag2)
        printf("Yes\n");
    else
        printf("No\n");
}

 

转载于:https://www.cnblogs.com/qscqesze/p/5036324.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值