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 ...
随机推荐
- TIJ -- 吐司BlockingQueue
1. 吐司BlockingQueue 考虑下面这个使用BlockingQueue的示例.有一台机器具有三个任务:一个制作吐司,一个给吐司抹黄油,另一个在抹过黄油的吐司上吐果酱.我们可以通过各个处理过程 ...
- 【netcore基础】.Net core通过 Lucene.Net 和 jieba.NET 处理分词搜索功能
业务要求是对商品标题可以进行模糊搜索 例如用户输入了[我想查询下雅思托福考试],这里我们需要先将这句话分词成[查询][雅思][托福][考试],然后搜索包含相关词汇的商品. 思路如下 首先我们需要把数据 ...
- LDA总结 (一) 共轭分布
今天开始,复习一下 LDA ,记录一些 LDA 的关键步骤,为写好论文做铺垫.第一节的主题是共轭分布,回忆贝叶斯公式: \[p(\theta|X) = \frac{p(\theta) \cdot p( ...
- Skip the Class
BestCoder Round #92 Skip the Class Accepts: 678 Submissions: 1285 Time Limit: 2000/1000 MS (Java/ ...
- ajax-addclass
- Radar Installation---(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 115873 Accepted: 2 ...
- ArcGIS AddIN 10.3项目与10.1项目的相互转换
1. .sln修改 用记事本打开.sln文件,在最上面将10的I昂么修改为12的项目 将下图 修改为下图 反之亦然 2. .csproj项目修改 用记事本打开.csproj文件, vs 2010文件如 ...
- HTML01
1.什么是HTML?(Hyper Text Markup Language:超文本标记语言) 超文本:功能比普通文本更加强大 标记语言:使用一组标签对内容进行描述的一门语言(它不是编程语言) 2.为什 ...
- linux ---部署django项目篇
uWSGI + nginx+ django + virtualenv + supervisor发布web服务器 项目部署步骤 1.项目准备阶段 1.准备项目代码,从本地拷贝 2.将项目上传到linux ...
- C++(+类型加强 +加入面向对象)
1.c++中所有变量可以在使用前定义. ; i< ; i++) { ; j< ; j++) { do_sth; } } 2. c++ 中可以获得 register 变量的地址. regis ...