Gym - 100989H
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.
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 题意:n个人买东西去柜台是否能全部找钱,k表示要付的钱,后面的数对应钞票1,5,10,20,50的数量,起初柜台里是没钱的。 思路:必须先判断能不能找零,之后才能拿钱,一开始没注意一直卡在第九组数据。如果第一个人给的钱不能刚好支付完,则没有零钱找给他,所以这种情况就直接no,后面假装输入一下就可以continue掉。如果需要找零钱,先找面值最大的,如果最后能找完,则收下他付的钱。
代码如下:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n;
int s[5]={1,5,10,20,50};
int v[5]={0};
int a[5];
long long int k;
cin>>n;
int flag=0,c=0;
while(n--)
{
c++;
cin>>k;
long long int t=0;
for(int i=0;i<5;i++)
{
cin>>a[i];
t+=a[i]*s[i];
}
if(flag)
continue;
k=t-k;
if(k==0)
{
for(int i=0;i<5;i++)
v[i]+=a[i];
}
else
{
if(c==1)
{
flag=1;
continue;
}
while(k>0)
{
while(k>=s[4]&&v[4])
{
k-=s[4];
v[4]--;
}
if(k==0)
break;
while(k>=s[3]&&v[3])
{
k-=s[3];
v[3]--;
}
if(k==0)
break;
while(k>=s[2]&&v[2])
{
k-=s[2];
v[2]--;
}
if(k==0)
break;
while(k>=s[1]&&v[1])
{
k-=s[1];
v[1]--;
}
if(k==0)
break;
while(k>=s[0]&&v[0])
{
k-=s[0];
v[0]--;
}
if(k==0)
break;
if(k>0)
{
flag=1;
break;
}
}
if(flag==0)
{
for(int i=0;i<5;i++)
v[i]+=a[i];
}
}
}
if(flag==1)
cout<<"no"<<endl;
else
cout<<"yes"<<endl;
return 0;
}
Gym - 100989H的更多相关文章
- Gym - 100989H (贪心)
After the data structures exam, students lined up in the cafeteria to have a drink and chat about ho ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
随机推荐
- Oracle误删除数据的恢复方法(转)
来源:原创网站北京北亚数据恢复中心,转载须注明出处. 学习数据库时,我们只是以学习的态度,考虑如何使用数据库命令语句,并未想过工作中,如果误操作一下,都可能导致无可挽回的损失.当我在工作中真正遇到这些 ...
- Delphi过程函数传递参数的几种方式
Delphi过程函数传递参数的几种方式 在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out. 另一种不加修饰符的为默认按值传递参数. 一.默认方式以值方式传递参数 proced ...
- 【Zookeeper系列】ZooKeeper机制架构(转)
原文链接:https://www.cnblogs.com/sunddenly/p/4133784.html 一.ZooKeeper权限管理机制 1.1 权限管理ACL(Access Control L ...
- C#获取一个数组中的最大值、最小值、平均值
C#获取一个数组中的最大值.最小值.平均值 1.给出一个数组 ,,,,,-,,,,}; 2.数组Array自带方法 本身是直接可以调用Min(),Max(),Average()方法来求出 最小值.最大 ...
- 如何看待淘宝二手交易APP“闲鱼”推出的新功能“闲鱼小法庭”?
转:https://www.zhihu.com/question/55487716?utm_source=qq&utm_medium=social
- 守护线程daemon
如下代码: from threading import Thread import time def func1(n): time.sleep(10) print(n) t = Thread(targ ...
- Nestjs 序列化(Serialization)
文档 在发送实际响应之前,Serializers为数据操作提供了干净的抽象层.例如,应始终从最终响应中排除敏感数据(如用户密码) λ yarn add class-transformer cats.e ...
- 关于 systemctl --user status 报错的问题
关于 systemctl --user enable mpd 报错: Failed to connect to bus: No such file or directory 因为arch脚本中,sys ...
- Linux提权:从入门到放弃
*原创作者:piece of the past,本文属Freebuf原创奖励计划,未经许可禁止转载 日站就要日个彻底.往往我们能拿下服务器的web服务,却被更新地比西方记者还快的管理员把内网渗透的种子 ...
- 1 创建一个存储过程,以及对存储过程的调用 MySQL
1 首先创建一张tb1表 sql语句如下 CREATE TABLE `tb1` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `age` int(11) DE ...