贪心(change)
http://codeforces.com/gym/100989/problem/H
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.
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.
Examples
- 3
4 0 1 0 0 0
9 4 1 0 0 0
8 0 0 1 0 0
- no
- 3
9 4 1 0 0 0
4 0 1 0 0 0
8 0 0 1 0 0
- yes
- //#include <bits/stdc++.h>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <algorithm>
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <cstring>
- #include <stdio.h>
- #include <queue>
- #include <stack>;
- #include <map>
- #include <set>
- #include <ctype.h>
- #include <string.h>
- #include <vector>
- #define ME(x , y) memset(x , y , sizeof(x))
- #define SF(n) scanf("%d" , &n)
- #define rep(i , n) for(int i = 0 ; i < n ; i ++)
- #define INF 0x3f3f3f3f
- #define mod 10
- #define PI acos(-1)
- using namespace std;
- typedef long long ll ;
- int sum , sum1 , sum5 , sum10 , sum20 , sum50 ;
- int main()
- {
- int n ;
- scanf("%d" , &n);
- int flag = ;
- for(int i = ; i < n ; i++)
- {
- int x , n1 , n5 , n10 , n20 , n50;
- scanf("%d%d%d%d%d%d" , &x , &n1 , &n5 , &n10 , &n20 , &n50);
- sum = * n1 + *n5 + *n10 + *n20 + *n50 - x;
- while(sum >= && sum50)
- {
- sum -= ;
- sum50 -- ;
- }
- while(sum >= && sum20)
- {
- sum -= ;
- sum20 -- ;
- }
- while(sum >= && sum10)
- {
- sum -= ;
- sum10 -- ;
- }
- while(sum >= && sum5)
- {
- sum -= ;
- sum5 -- ;
- }
- while(sum >= && sum1)
- {
- sum -= ;
- sum1 -- ;
- }
- if(sum == )
- {
- sum1 += n1 ;
- sum5 += n5 ;
- sum10 += n10;
- sum20 += n20;
- sum50 += n50;
- }
- else
- {
- flag = ;
- }
- }
- if(flag)
- {
- printf("no\n");
- }
- else
- {
- printf("yes\n");
- }
- return ;
- }
贪心(change)的更多相关文章
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心
A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心
A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF 500 C. New Year Book Reading 贪心 简单题
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...
- leetcode:Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function ...
- HDU 5821 Ball (贪心)
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- Codeforces Gym 100203E E - bits-Equalizer 贪心
E - bits-EqualizerTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- POJ - 2965 - The Pilots Brothers' refrigerator (高效贪心!!)
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19356 ...
- CF Covered Path (贪心)
Covered Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- 高考数学九大超纲内容(1)wffc
我校2016$\thicksim$2017学年度(上期)半期高三(理科)考试第12题 已知奇函数\(f(x)\)的定义域是\((-1,0)\bigcup\hspace{0.05cm}(0,1)\),\ ...
- Git之仓库管理
介绍以及安装: Git 是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. Git 最初是由Linus Torvalds设计开发的,用于管理Linux内核开发.Git ...
- java:集合输出之Iterator和ListIterator二
java:集合输出之Iterator和ListIterator二 ListIterator是Iterator的子接口,Iterator的最大特点是,能向前,或向后迭代.如果现在要想双向输出的话,则只能 ...
- ViewContainerRef 动态创建视图
Angular DOM 操作 相关的APIs和类: 查询DOM节点 template variable ref: 模版变量引用,相当于react中的ref ViewChild: 查询DOM,返回单个元 ...
- php大文件下载+断点续传
如果我们的网站提供文件下载的服务,那么通常我们都希望下载可以断点续传(Resumable Download),也就是说用户可以暂停下载,并在未来的某个时间从暂停处继续下载,而不必重新下载整个文件. 通 ...
- 【PowerOJ1742&网络流24题】试题库问题(最大流)
题意: 思路: [问题分析] 二分图多重匹配问题,用最大流解决. [建模方法] 建立二分图,每个类别为X集合中的顶点,每个题为Y集合中的顶点,增设附加源S和汇T. 1.从S向每个Xi连接一条容量为该类 ...
- Essential Java.《Java 编程要点》
Essential Java.<Java 编程要点> Essential Java, is a book about the Essentials of Java Programming. ...
- CentOS 6 修改时间和时区及设置修改及时间同步
一.时区 date -R; date ; hwclock --show ; ps -ef|grep ntpd 显示时区 date --help 获取帮助 date -R date +%z 上面两个命令 ...
- View 层
package com.test.mvp.mvpdemo.mvp.v1.view; import android.app.ProgressDialog;import android.os.Bundle ...
- 关于Idea热部署,修改代码不需要重启tomcat