贪心(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 ...
随机推荐
- 转 Java中final、finally、finalize的区别与用法
Java中final.finally.finalize的区别与用法 1.简单区别:final用于声明属性,方法和类,分别表示属性不可交变,方法不可覆盖,类不可继承.finally是异常处理语句结构 ...
- C++ GUI Qt4学习笔记01
C++ GUI Qt4学习笔记01 qtc++signalmakefile文档平台 这一章介绍了如何把基本的C++只是与Qt所提供的功能组合起来创建一些简单的图形用户界面应用程序. 引入两个重要概 ...
- MongoDB的$作为下标的用法
在MongoDB中有一个非常神奇的符号 "$" "$" 在 update 中 加上关键字 就 变成了 修改器 其实 "$" 字符 独立出现 ...
- git的fetch
1.git fetch 会从远程分支上下载 2.git pull 会将本地库更新至远程库最新状态
- Hybris commerce产品主数据的搜索API,批量返回若干主数据的值
新建一个产品,identifier设置为i042416-1,创建之后立即能够在Backoffice里搜索出来: 等到Storefront的indexing做完之后,前台通过关键字i042416也能将这 ...
- rk3328设备树学习
一.用到的rk3328好像使用了设备树 设备树我知道的有三种文件类型,dtbs是通过指令make dtbs编译的二进制文件,供内核使用. 基于同样的软件分层设计的思想,由于一个SoC可能对应多个mac ...
- Software-Defined Networking: A Comprehensive Survey
文章名称:Software-Defined Networking: A Comprehensive Survey 文章来源:Proceedings of the IEEE ( Volume: 103 ...
- (41)freeRTOS之任务管理
1. 简介: 在 FreeRTOS 中没有线程和进程的区别,只有一个被翻译成任务的程序,相当于进程的概念,拥有独立的栈空间. 对于实时性,可以分为 软实时.硬实时:桌面电脑的输入处理可以看做是软实时, ...
- Redis分布式锁服务
阅读目录: 概述 分布式锁 多实例分布式锁 总结 概述 在多线程环境下,通常会使用锁来保证有且只有一个线程来操作共享资源.比如: object obj = new object(); lock (ob ...
- mysq访问方式
mysql -h10.81.32.196 -P5152 -Dns_map_data_new -uwangyuchuan_r -p3DLg15rhSsm0O7Nsselect uid,name from ...