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 ...
随机推荐
- 二进制样式的字符串与byte数组互转函数示例
开发时用到的方法,记录下: /// <summary> /// 测试方法 /// </summary> private void TestFun() { Response.Wr ...
- MSF实现RID劫持和MSF实现PsExec执行命令
msf实现rid劫持 rid劫持原理: 每个帐户都有一个指定的RID来标识它.与域控制器不同,Windows工作站和服务器会将大部分数据存储在HKLM\SAM\SAM\Domains\Account\ ...
- Xcode - Xcode10上传应用到AppStore
Xcode 10 如何上传应用到AppStore?Product->Archive 后,原来Xcode 10 之前的版本是直接有两个按钮,一个upload to AppStore,另一个叫Exp ...
- H - Expedition 优先队列 贪心
来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...
- 把一张图片变成base64
// image_file可为urlprivate function base64EncodeImage($image_file) { $image_info = getimagesize($imag ...
- Express中间件的原理及实现
在Node开发中免不了要使用框架,比如express.koa.koa2拿使用的最多的express来举例子开发中肯定会用到很多类似于下面的这种代码 var express = require('exp ...
- pandas读取文件报错
path = 'D:/Postgraduate/Python/Machine Learning/小象学院机器学习/08.回归实践/8.Regression代码/8.Regression/8.Adver ...
- Python学习之旅(二十二)
Python基础知识(21):IO编程 一.文件读写 读写文件就是请求操作系统打开一个文件对象(文件描述符),然后,通过操作系统提供的接口从这个文件对象中读取数据(读文件),或者把数据写入这个文件对象 ...
- python全栈开发 * 12 知识点汇总 * 180530
12 知识点总结 装饰器进阶 ⼀. 通⽤装饰器的回顾1.开闭原则: 对增加功能开放. 对修改代码封闭2.装饰器的作⽤: 在不改变原有代码的基础上给⼀个函数增加功能3.通⽤装饰器的写法:def wrap ...
- sql server中的charindex函数用法解析(在一段字符中搜索字符或者字符串-----返回expression1在expression2出现的位置;反之,返回0)
https://blog.csdn.net/xinghuo0007/article/details/70651358 知识点一:charindex()语法 CHARINDEX ( expression ...