OCAC summer second game I question grape wine cup moonlight solution to a problem

Cup grape wine moonlight
original title link: http: //codeforces.com/problemset/problem/1114/A
[title] Description
grape wine Magic Cup, want to drink immediately pipa reminder.
Zuiwo battlefield Jun Mo laugh, ancient expedition a few people back?
Poetry poetry! But today we This question has nothing to do wine, there is no moonlight Cup, but about grapes.
Saying this grape ......
For simplicity, we assume that now only three grape varieties: green grapes, purple grapes and black grapes.
Li Bai, Du Fu and Wang teacher three were lovers of the grape, however, they taste of the grape but not the same. In order to make all three of them happy, you must meet the following conditions:
1, Li Bai at least need to eat x grapes, Du Fu least need to eat y grapes, at least Wang teachers need to eat z grapes;
2, Li Bai for green grapes have a special habit, so he would only eat green grapes;
3, Du did not like black grapes, so he will not eat black grapes;
4, Wang teacher generosity, which he would eat grapes.
He Sa mutual friend - Bai - in learned they are so fond of grapes, when they decided to report a grape party.
He prepared a box of grapes, which comprises a teeth green grapes, b teeth grapes, grape black particles and c.
However, Po Chu and unsure whether he was prepared this box of grapes to make his three friends were happy.
Ask you to help determine if there is a way to let three people were satisfied with the distribution plan.
Note: Your aim is allocated to three friends so that they are satisfied with the grapes, but do not necessarily need to complete the distribution box of grapes.
[Input Format]
The first line contains three input integers x, y, z (1 < = x, y, z <= 10 ^ 5), are used to represent the number of Du Fu Wang teacher and at least eat grapes.
The second line of input contains three integers a, b, c (1 < = a, b, c <= 10 ^ 5), are used to represent the number of green grapes, black grapes and grape.
[Output Format]
If there let three people were satisfied with the grape allocation, output "YES"; otherwise, the output "NO".
Sample input [1]
1 2. 6
. 4. 3. 3
[1] sample output
YES
[2] Sample input
. 5 1 1
. 4. 3 2
[2] sample output
NO
[Analysis]
The present method relates to the question: greedy.
First, because Li Bai eating green grapes. To give consideration so Bai x pieces of green grapes, if not minutes to "NO", it points had a - = x;
secondly, Fu eat black grapes, the remaining number of green grapes and grapes to meet a + b> = y;
at the same time, do not forget the teacher Wang also eat grapes z.
Therefore, a total number of teachers and Wang Fu eating grapes but also to meet a condition: a + b + c> = y + z.
Codes are as follows:

#include <bits/stdc++.h>
using namespace std;

int x, y, z, a, b, c;

bool check() {
    if (a < x) return false;
    a -= x;
    if (a + b < y) return false;
    if (a + b + c < y + z) return false;
    return true;
}

int main() {
    cin >> x >> y >> z >> a >> b >> c;
    puts( check() ? "YES" : "NO" );
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/ocac/p/11131668.html