贪心(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 ...
随机推荐
- 【leetcode】313. Super Ugly Number
题目如下: 解题思路:总结一下这么几点,一出一进,优先级队列排序,保证每次输出的都是当前的最小值.解法大致如图: 代码如下: #include<map> #include<queue ...
- Pytest安装介绍--使用(html报告)
Pytes是 一个单元测试框架,可以生成html报告. #卸载# pip uninstall pytest#安装# pip install -U pytest# 查看# pytest --versio ...
- 手把手搭建K3cloud插件开发环境
最近几天在配置K3cloud开发环境,发现不论是产品论坛还是百度出来的结果,都不够满意,很多大咖给提供的环境搭建手册都是那个云山雾罩的PPT 也就是这个open.kingdee.com/K3Cloud ...
- POJ 3764 The xor-longest Path ( 字典树求异或最值 && 异或自反性质 && 好题好思想)
题意 : 给出一颗无向边构成的树,每一条边都有一个边权,叫你选出一条路,使得此路所有的边的异或值最大. 分析 : 暴力是不可能暴力的,这辈子不可能暴力,那么来冷静分析一下如何去做.假设现在答案的异或值 ...
- Spark Streaming的优化之路—从Receiver到Direct模式
作者:个推数据研发工程师 学长 1 业务背景 随着大数据的快速发展,业务场景越来越复杂,离线式的批处理框架MapReduce已经不能满足业务,大量的场景需要实时的数据处理结果来进行分析.决 ...
- Handling Configuration Changes with Fragments
This post addresses a common question that is frequently asked on StackOverflow: What is the best wa ...
- package.json保存
# 确保已经进入项目目录 # 确定已经有 package.json,没有就通过 npm init # 创建,直接一路回车就好,后面再来详细说里面的内容. # 安装 webpack 依赖 npm ins ...
- 我用HTML写简历
本文属于原创文章,转载请注明--来自桃源小盼的博客 起因 每次换工作写简历都是有点痛苦的事情,尤其是下载word模板,各种注册流程,有的还得买积分,冲会员,甚是不爽.就算下载好了,修改其中的一些细节也 ...
- 转: Github上关于iOS的各种开源项目集合
https://blog.csdn.net/jiashaoying/article/details/79079500 下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. ...
- 嵌入式Linux之telnet
telnetd 1.busybox搭建根文件系统时telnet配置Networking Utilities——>[*]telnetd[*]Support standalone telnetd ...