http://codeforces.com/contest/349

这是一个关于电影票售卖的问题,人们排队购票,每人持有25、50或100卢布的钞票,电影票价格为25卢布。营业员初始无零钱,程序模拟售票过程,判断是否能顺利完成交易。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Cinema Line
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of people in the line. The next line contains n integers, each of them equals25, 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.

Output

Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".

Examples
input
4
25 25 50 50
output
YES
input
2
25 100
output
NO
input
4
50 50 25 25
output
NO

简介:买电影票一张25一张,然后营业员最初没有钱,给你一个只有25 ,50,100的数列,问能否成功卖票,成功输出“yes”否则输出“NO”

题解:直接模拟,x代表25的票数y代表50的票数z代表100的票数

代码如下:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 const int maxn=1e5+5; 
 6 int a[maxn];
 7 int x,y,z,n; 
 8 int main()
 9 {
10     scanf("%d",&n);
11     int flag=true;
12     x=y=z=0; 
13     for(int i=0;i<n;i++)
14     {
15         scanf("%d",&a[i]);
16         if(flag) 
17         {
18             if(a[i]==25)
19             {
20                 x++; 
21             }
22             else if(a[i]==50) 
23             {
24                 y++;
25                 if(x>=1)
26                 {
27                     x--; 
28                 }
29                 else
30                 {
31                     flag=false; 
32                 } 
33             } 
34             else 
35             {
36                 z++; 
37                 if(y>=1&&x>=1)
38                 {
39                     y--;
40                     x--; 
41                 }
42                 else if(x>=3) 
43                 {
44                     x=x-3; 
45                 } 
46                 else
47                 {
48                     flag=false; 
49                 } 
50             } 
51             
52         } 
53         
54     } 
55     if(flag)
56     {
57         cout<<"YES\n"; 
58     } 
59     else
60     {
61         cout<<"NO\n"; 
62     } 
63 } 

题目连接http://codeforces.com/contest/349/problem/A

转载于:https://www.cnblogs.com/lhclqslove/p/7142383.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值