H-Queue (A)Time
limit:MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i64u SubmitStatusPracticeGym 100989H
Description
Standard Input/output
After the data structures exam, students lined, the cafeteria has a drink and chat about how much they has enjoy Ed the exam
And how good their professors is. Since It was late in the evening, the cashier had already closed the cash register and does not having
Any change with him.
The students is going to pay using Jordanian money notes, which is of the following types:1, 5, 10, 20, 50.
Given how much each student have to pay, the set of notes he's going to pay with, and the order in which the students Arriv E at the
Cashier, your task is-find out if the cashier would have enough change to return 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 the queue.
Each of the Following N lines Describes a student and Contains 6 integers, K , F 1 , F 2 , F 3 , F 4 , And F 5 , Where K represents the
Amount of money the student have to pay, and Fi(0?≤? Fi≤?100) represents the amount of the ith type of money this St Udent is going
To give to the cashier.
The students is given in order; The first student is in front of the cashier.
It is guaranteed that no student would pay any extra notes. In other words, after removing any note from the set the student are going to
Give to the cashier, the amount of money would be less than what's required to buy the drink.
Output
Print Yes if the cashier'll has 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
Greedy
Every change, is a priority to use the big ticket, because the small ticket has all the functions of large tickets, and has a large ticket does not have the function, so each priority to use large floating
By using one of your own keys to test the version of multiple sets of data
There is no reset in front of the data, so for a long time (┬_┬)
#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) * *0; } if (Fstore[2] >= k/5) {fstore[2]-= k/5;k-= (K/5);} if (Fstore[1] >= k) fstore[1]-= k; else {ans = false; break;} }} if (ans) printf ("Yes"); else printf ("no"); #ifdef LOCAL printf ("\ n"); There is no reset in front of the data, in vain to check for such a long time (┬_┬)} #endif//LOCAL return 0;}
Thank you!
------ from Prolights
UESTC Summer Training #1 Div.2 h-queue (A) Greed