The new "Die Hard" movie has just been released! There are
n people at the cinema box office standing in a huge line. Each of them has a single
100, 50 or
25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
Output
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
Sample test(s)
Output
NO
题意:
上映一部AV, 售价25日元;
钱币在这里按规矩只有三种面额: 25, 50 ,100
很多人排队购买, 初始状态下, 售片方没有钱找零
问, 按给出的队列, 能顺利得让每个人都买到片吗?
做法:
明显找钱的情况只有两种, 收到50的时候找25, 收到100的时候, 找25和50各一张, 即25 + 50 = 75;
并且, 没有情况是需要把100找出去的, 所以只要讨论25 和 50够不够用;
所以, 25 和 50面额的钱币, 收一张, 记一张, 并在找出去的时候记得减去一张;
没应付完一个顾客都要检查是否25 和 50面额的钱币不够用了~
AC代码:
#include<stdio.h>
int main() {
int num25;
int num50;
int n;
int mark;
while(scanf("%d", &n) != EOF) {
num25 = 0;
num50 = 0;
mark = 1;
while(n--) {
int num;
scanf("%d", &num);
if(num == 100) {
num25--;
num50--;
}
else if(num == 50) {
num25--;
num50++;
}
else if(num == 25)
num25++;
if(num25 < 0 || num50 < 0)
mark = 0;
}
if(mark)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
分享到:
相关推荐
Reference=*\G{91493440-5A91-11CF-8700-00AA0060263B}#2.8#0#..\..\..\..\..\Tools\Office2003\OFFICE11\MSPPT.OLB#Microsoft PowerPoint 11.0 Object Library Reference=*\G{00020905-0000-0000-C000-000000000046...
传送门 题意: 找规律,题意就是有多少种方式填充该图形 画两个就发现,输出n即可 代码: #include #include #include #include #include #include #include #include ...#define SZ(x) ((int)(x)
.orange a:hover p,.orange a:hover .row2,.orange a:hover .row3,.orange a:hover .row4{ background:#fa0; } .yellow p,.yellow .row2,.yellow .row3,.yellow .row4{ background:#aaa; } .yellow a:hover p,....
cfmmc.cer这是个登陆cfmmc.com的证书,需在jdk中导下
C1.CF.C1FlexGrid.3.dll
应用Scratchbox构建基于CF卡的嵌入式linux系统.doc应用Scratchbox构建基于CF卡的嵌入式linux系统.doc应用Scratchbox构建基于CF卡的嵌入式linux系统.doc应用Scratchbox构建基于CF卡的嵌入式linux系统.doc应用...
CF方框透视授权 模块 源码.e.......................................
cf_st_2.dat
CF-A7-MX C.A780T D3 V19
CF脚本工具2.9.rar......................
CF卡枪易语言源码NO.06.rar
基于8051的CF卡文件系统的实现.zip电子电路图PCB单片机设计案例资料基于8051的CF卡文件系统的实现.zip电子电路图PCB单片机设计案例资料基于8051的CF卡文件系统的实现.zip电子电路图PCB单片机设计案例资料基于8051的...
..................................
cf_hs_2.dat
28 1.2.4 标准的好处......................................................................................... 29 第2 章 802.11 网络概论....................................................................
资源分类:Python库 所属语言:Python 资源全名:cftime-1.2.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
【资源说明】 1.项目代码均经过功能验证ok,确保...CF易键鼠宏以及资料.zipCF易键鼠宏以及资料.zipCF易键鼠宏以及资料.zipCF易键鼠宏以及资料.zipCF易键鼠宏以及资料.zipCF易键鼠宏以及资料.zipCF易键鼠宏以及资料.zip