Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3 third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals.
Naturally, the rewards in the cupboard must look good, that‘s why Bizon the Champion decided to follow the rules:
- any shelf cannot contain both cups and medals at the same time;
- no shelf can contain more than five cups;
- no shelf can have more than ten medals.
Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.
The first line contains integers a1, a2 and a3 (0 ≤ a1, a2, a3 ≤ 100). The second line contains integers b1,b2 and b3 (0 ≤ b1, b2, b3 ≤ 100). The third line contains integer n (1 ≤ n ≤ 100).
The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
1 1 1
1 1 1
4
YES
1 1 3
2 3 4
2
YES
1 0 0
1 0 0
1
NO
对于这道题笔者认为采用贪心算法来解决这道问题比较实在:
下面就贴出笔者的代码吧:
#include<cstdio>
#include<iostream>
using namespace std;
int a[3],b[3];
int main(void)
{
int n;
int need = 0;
int sum1 = 0,sum2 = 0;
for(int i=1;i<=3;++i){
scanf("%d",&a[i]);
sum1 += a[i];
}
for(int i=1;i<=3;++i){
scanf("%d",&b[i]);
sum2 += b[i];
}
scanf("%d",&n);
if(sum1%5!=0) need += sum1/5+1;
else need += sum1/5;
if(sum2%10!=0) need += sum2/10+1;
else need += sum2/10;
if(need<=n) printf("YES\n");
else printf("NO\n");
return 0;
}
其实笔者在做这道题的时候,感到非常汗颜,因为一个粗心导致提交两遍都没有A掉这题,心中是在惭愧。。。。