Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
2015-12-10 15:54
495 查看
A. Magic Spheres
Time Limit: 20 SecMemory Limit: 256 MB
题目连接
http://www.codeforces.com/contest/606/problem/ADescription
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 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.
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"); }
相关文章推荐
- Fragment里面嵌套Fragment的问题
- Maven 实用命令和技巧
- go的Type switch是一个switch语句么?
- 单独使用ndk的编译器
- Objective-C关键字__Nullable和__Nonnull
- C++设计模式之Singleton
- House Robber
- 黑马程序员————————创建多线程的两种方式
- ios 检查内存泄露
- android中webview加载html,输入框不能输入内容问题记录
- 变量一般不要定义在.h文件中
- leetcode -- Find Minimum in Rotated Sorted Array II -- 重点,自己思路不清晰
- android四大组件
- Android status icon remove
- window7上爬虫框架Scrapy的安装 --错误分析lxml
- 构造方法 练习
- 判断、添加和删除WordPress置顶文章的相关PHP函数小结
- 关于GCD开发的一些事儿
- 如此简单的Scroller
- 蓝牙技术——数据传输