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 ...
随机推荐
- GLSL数组类型、浮点数Uniform
// 添加shader中的uniform ss->addUniform(new osg::Uniform("test1", false)); //设置shader中的unif ...
- POI导出复杂的excel;excel公共样式类;excel拼接定制类;数据科学计数法转为普通值
一.excel公共样式类(包含数据科学计数法转为普通值) package com.thinkgem.jeesite.common.utils.excel; import org.apache.poi. ...
- Android 7.0 适配
extends:http://www.jianshu.com/p/56b9fb319310http://blog.csdn.net/chay_chan/article/details/57083383
- gitlab的fork及源项目的同步
此篇大部分貌似是cp其他地方的,也忘了出处,写到此处,权当保存,见谅. 测试代码master同步到生产代码master #现有git@gitlab.home.com:root/fork.git项目 ...
- HTML load事件和DOMCOntentLoaded事件
JS高程 p14 “异步脚本一定会在页面的load事件前执行,但可能会在DOMContentLoaded事件触发之前或之后执行” 普通script标签会阻塞DOM的解析 DOMcontentLoa ...
- ubuntu apt 软件源的更改
在ubuntu上面安装软件一般都使用 apt安装 在ubuntu下面有一个源列表,源列表里面都是一些网站信息,每条网址就是一个源,这个地址指向的数据标识着这台服务器上有哪些软件可以用 编辑源命令: s ...
- 特殊字符url编码以后再解码后出现错误(¬ , ¢, ¤, £)
Url编码的原内容是 “¬ify_url=xxxx” 经过url编码以后再解码回来 “¬”的部分就变成了“¬” 解决方案:把原文里面待url编码的&符号先替换成 ...
- 我也来----xia bi bi 一下----微信小程序
工作刚到一阶段 就看了看微信小程序 自己做了个小dome 主要是为了让我女朋友能够学习做菜! 然而悲催的发现我根本没有App ID 不说快了 直接上图 个人感觉开发起来还是很简单的. 对着AP ...
- JAVAMail邮件服务器
SMTP:simple mail transfer protocol(简单邮件传输协议),是internate传输mail的基本协议,也是TCP/IP协议组成员, POP3:邮局协议第三版,是inte ...
- [ovs] 编写openflow流表的文档指引
首先,openflow流表都是使用ovs-ofctl命令进行添加的. 1. 看 ovs-ofctl 的man手册 man ovs-ofctl 或者,这个地方也有:http://www.openvswi ...