UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心

来源:互联网 发布:淘宝购物被骗找网警 编辑:程序博客网 时间:2024/05/16 08:05

H - Queue (A)
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice Gym 100989H

Description

standard input/output 

After the data structures exam, students lined up in the cafeteria to have a drink and chat about how much they have enjoyed the exam 

and how good their professors are. Since it was late in the evening, the cashier has already closed the cash register and does not have 

any change with him.

The students are going to pay using Jordanian money notes, which are of the following types: 1, 5, 10, 20, 50.

Given how much each student has to pay, the set of notes he’s going to pay with, and the order in which the students arrive at the 

cashier, your task is to find out if the cashier will have enough change to return to each of the student when they arrive at the cashier.

Input

The first line of input contains a single integer N(1 ≤ N ≤ 105), the number of students in the queue.

Each of the following N lines describes a student and contains 6 integers, KF1F2F3F4, and F5, where K represents the 

amount of money the student has to pay, and Fi(0 ≤ Fi ≤ 100) represents the amount of the ith type of money this student is going 

to give to the cashier.

The students are given in order; the first student is in front of the cashier.

It is guaranteed that no student will pay any extra notes. In other words, after removing any note from the set the student is going to 

give to the cashier, the amount of money will be less than what is required to buy the drink.

Output

Print yes if the cashier will have enough change to return to each of the students when they arrive in the given order, otherwise print 

no.

Sample Input

Input
34 0 1 0 0 09 4 1 0 0 08 0 0 1 0 0
Output
no
Input
39 4 1 0 0 04 0 1 0 0 08 0 0 1 0 0
Output
yes

Source

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121539#problem/H


My Soluton

贪心

每次找钱,都是优先使用 大票, 因为小票具有大额票的所有功能, 而且具有大额票所不具有的功能, 所以每次优先使用大额飘

//由于用了自己的一键测试多组数据的版

//!前面有些数据没有重置, 白白检查了这么长时间(┬_┬)


#include <iostream>#include <cstdio>#include <cstring>using namespace std;typedef long long LL;const int maxn = 1e6 + 8;int Fstore[6];int main(){    #ifdef LOCAL    freopen("a.txt", "r", stdin);    //freopen("b.txt", "w", stdout);    int T = 1;    while(T--){    #endif // LOCAL    memset(Fstore, 0, sizeof Fstore);    int n, k, f1, f2, f3, f4, f5;    bool ans = true;    scanf("%d", &n);    while(n--){        scanf("%d%d%d%d%d%d", &k, &f1, &f2, &f3, &f4, &f5);        Fstore[1] += f1;Fstore[2] += f2; Fstore[3] += f3; Fstore[4] += f4; Fstore[5] += f5;        //for(int i = 5; i >= 0; i--){            k = f1 + f2*5 + f3*10 + f4*20 + f5*50 - k;//if(T == 0) cout<<f1 + f2*5 + f3*10 + f4*20 + f5*50<<" "<<k<<endl;            if(Fstore[5] >= k/50) {Fstore[5] -= k/50;k -= (k/50)*50; }            if(Fstore[4] >= k/20) {Fstore[4] -= k/20;k -= (k/20)*20; }            if(Fstore[3] >= k/10) {Fstore[3] -= k/10;k -= (k/10)*10; }            if(Fstore[2] >= k/5) {Fstore[2] -= k/5;k -= (k/5)*5; }            if(Fstore[1] >= k) Fstore[1] -= k;            else {ans = false; break;}        //}    }    if(ans) printf("yes");    else printf("no");    #ifdef LOCAL    printf("\n");    //!前面有些数据没有重置, 白白检查了这么长时间(┬_┬)    }    #endif // LOCAL    return 0;}

  Thank you!

                                                                                                                                               ------from ProLights

0 0
原创粉丝点击