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

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

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

时间: 2024-11-12 10:28:56

UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心的相关文章

UESTC 2016 Summer Training #5 Div.2(未完待续)

A #include <cstdio> #include <cstring> #include <vector> #define MAXN 100005 #define mem(a) memset(a, 0, sizeof(a)) using namespace std; int TreeArray[MAXN], Left[MAXN], Right[MAXN], Fork[MAXN]; typedef vector<int> Ve; vector<Ve

UESTC 2016 Summer Training #1 Div.2

最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria (B) 不会捉 Gym 100989E 水 Gym 100989F 水 Mission in Amman (B) 没看题 Queue (A) 感觉题意理解得有问题啊 1 #include <iostream> 2 #include <cstdio> 3 #include <cstr

UESTC 2016 Summer Training #2 Div.2 A dp、递推、多阶段问题

A - A Time Limit:336MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11A Description Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did we not tell you that

UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论

E - Accepted Passwords Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989E Description standard input/output Islam is usually in a hurry. He often types his passwords incorrectly. He hates

UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)

F - Mission in Amman (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989F Description standard input/output You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the che

UESTC 2016 Summer Training #1 Div.2 L - Plus or Minus (A) dfs

L - Plus or Minus (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989L Description standard input/output AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect eq

UESTC 2016 Summer Training #2 Div.2 E 分解质因素(除了以后剩下的可能也是个素数)

E - E Time Limit:3000MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11E Description Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and

UESTC 2014 Summer Training #16 Div.2

虽然被刷了还是要继续战斗下去嗯...就是基础不好,难度相对较大 A.SPOJ AMR10A 点是顺时针给出的,可以在图上画画(脑补也行),连线x-a,x-b(x为选定的一个点,比如第一个点),就把所求面积分成了四部分,a-b左边部分是较容易求出来的, 三角形面积是直接可求,另外两个多边形面积是可以预处理出来的(多个三角形面积和) 反正我是沒想出來...看題解也理解半天,多邊形面積转化为三角形面积和 嗯嗯 #include <iostream> #include <cstdio> #

UESTC 2014 Summer Training #7 Div.2

DAY7一开始状态还行,最高纪录rank7,然后没力气了,一直跌到rank24,问题还是很多呐.昨天总结的问题依然很大. Problem A UVA 12377 就一开始还是慌了,没审清楚题意就去WA了一发. 大意是给你一个数字表示的字符串,最高20位,第一表示有N个质数,后面是其幂的非降序排列,所求能表示的数个数. 简单的排列组合题,不过需要处理出2~END的不同划分,并且满足非降序,用dfs处理即可. 具体就是dfs过程中记录下每一个数字出现的次数,因为相同的次数是不计顺序的,需要在统计时除