UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心
来源:互联网 发布:淘宝购物被骗找网警 编辑:程序博客网 时间:2024/05/16 08:05
Description
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, K, F1, F2, F3, F4, 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
34 0 1 0 0 09 4 1 0 0 08 0 0 1 0 0
no
39 4 1 0 0 04 0 1 0 0 08 0 0 1 0 0
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) 贪心
- UESTC 2017 Summer Training #1 Div.2
- UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)
- UESTC 2016 Summer Training #1 Div.2 L - Plus or Minus (A) dfs
- UESTC 2016 Summer Training #1 Div.2(未完待续)
- UESTC 2016 Summer Training #1 Div.2 J - Objects Panel (A) dfs、按条件遍历树、interesting
- UESTC 2016 Summer Training #2 Div.2 A dp、递推、多阶段问题
- UESTC 2016 Summer Training #4 Div.2 A - (。•_•。) 预处理打表
- UESTC 2016 Summer Training #2 Div.2(未完待续)
- UESTC 2016 Summer Training #3 Div.2(未完待续)
- UESTC 2016 Summer Training #4 Div.2(未完待续)
- UESTC 2016 Summer Training #5 Div.2(未完待续)
- UESTC 2016 Summer Training #6 Div.2(未完待续)
- UESTC 2016 Summer Training #10 Div.2(未完待续)
- UESTC 2016 Summer Training #18 Div.2(未完待续)
- UESTC 2016 Summer Training #19 Div.2(未完待续)
- UESTC 2017 Summer Training #2 Div.2
- UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论
- linux yum 安装mysql
- java集合框架之Map
- 变量在函数体内和函数内嵌作用域内定义区别
- 数据库恢复的基础是利用转储的冗余数据。这些转储的冗余数据包括()----百度2016研发工程师笔试题(六)
- [暑假集训] jzoj 2016.7.12 noip模拟赛B 总结
- UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心
- POJ 1734 Sightseeing trip
- python3的默认编码
- Selenium自动化测试框架对于日期控件的封装
- Scala break 语句
- String to Integer (atoi)
- Android 打造形形色色的进度条 实现可以如此简单 无需继承view,直接继承progressbar
- [php学习三]表单提交练习
- 在一棵度为3的树中,度为3的节点个数为2,度为2的节点个数为1,则度为0的节点个数为()----百度2016研发工程师笔试题(六)