码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-13 17:12:27      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

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

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
3
4 0 1 0 0 0
9 4 1 0 0 0
8 0 0 1 0 0
Output
no
Input
3
9 4 1 0 0 0
4 0 1 0 0 0
8 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

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

标签:

原文地址:http://blog.csdn.net/prolightsfxjh/article/details/51892806

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!