CF round#202 A (13.09.28)
来源:互联网 发布:linux 网桥 问题 编辑:程序博客网 时间:2024/06/06 12:54
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 single100, 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?
The first line contains integer n (1 ≤ n ≤ 105) — the number of people in the line. The next line containsn integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
425 25 50 50
YES
225 100
NO
450 50 25 25
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;}
- CF round#202 A (13.09.28)
- CF 158A Round
- CF (Round#256) A. Rewards
- CF#158A Next Round
- cf- #346 A-Round House
- CF Educational Round 12,A
- CF round#211-2 A (13.11.11)
- CF round 355 A题 思维
- 【CF】Codeforces Round #124 (Div. 2) 197A Plate Game
- CF Round#333 Div2 B. Approximating a Constant Range
- CF Round #616 (A,B,C 字符串,贪心,DFS)
- cf Educational Codeforces Round 6 C Pearls in a Row
- CF Round#617(A B 。。。=_=)
- cf#Wunder Fund Round 2016 -A - Slime Combining-简单数学
- cf#AIM Tech Round -B. Making a String-贪心/set
- CF Round 8VC (A. Orchestra暴力)
- CF初体验——Round #348, A
- CF Round #361 (Div. 2) 689A 模拟
- poj 3468 A Simple Problem with Integers ( 线段树 )
- BNU 12680 Jupiter Atacks! (线段树)
- vc6.0生成ocx,然后使用js调用
- Android反编译最新版本
- 【python】【学习】今天学习了部分python的基础,和大家分享一下
- CF round#202 A (13.09.28)
- 44-首字下沉效果的设置
- 整型数组处理算法(六)合并两个数组
- 宝贵财富
- Android使用多个Intent进行Activity跳转,如何直接退出系统
- win音视频--qt视频显示
- vim windows
- POJ1873+几何凸包
- 约瑟夫环的推导