日练23.8.11

今日水题~

Cinema Line

题面翻译

新电影《虎胆龙威》刚刚上映了!  
有n位观众正~~焦急地~~站在电影院售票处并且排成了一列长队。他们或多或少都有一张100,50或是25卢布的钞票。  
一张《虎胆龙威》的票价是25卢布。  
那么问题是:如果这位售票员最初没有钱,并且严格地按照人们排队的顺序(有素质)卖票,售票员能否将一张票卖给每位观众并且找零吗?  
输入格式:
第一行包含了一位整数n (1<=n<=10^5)用于表示正在排队的观众的数量。  
第二行包含了n位整数,他们是25,50,100这三个数其中之一位用于表示每位观众所持有的钞票面额。(这些数字是顺序给出的)。  
输出格式:  
如果售票员可以使得这些观众都看上电影并且能找开他们的零钱,输出“YES”。否则,输出“NO”(不带引号)。~~“”:又不带我嘤嘤嘤...~~   
(样例#2解释:有两位观众,这两位观众分别有一张25卢布面额的钞票和一张100卢布的钞票,因为售票员最初没有任何钱,所以他在收了第一位观众的钱后(得到了25卢布),找不开第二位观众所需的75卢布,所以输出“NO”)

题目描述

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?

输入格式

The first line contains integer $ n $ $ (1<=n<=10^{5}) $ — the number of people in the line. The next line contains $ n $ 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".

样例 #1

样例输入 #1
4
25 25 50 50

样例输出 #1

YES

样例 #2

样例输入 #2
2
25 100
样例输出 #2
NO

样例 #3

样例输入 #3
4
50 50 25 25
样例输出 #3
NO

解题思路

肥肠简单,题目说啥我干啥,一步步走,设置两个参数存放25和50的数量(100找不了零),之后100可分为25*3或25+50,50找25,25直接存不用找,使用一个switch语句一步到胃……

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=1e5+5;
ll n,a,tf,ft;  //tf为25,ft为50

int main(){
    cin>>n;
    while(n--){
        cin>>a;
        switch(a){
			case 100:
				if((ft>=1&&tf>=1)||tf>=3)  //判断100能不能找
					if(ft>=1){ 
					    ft--;
					    tf--;
					}
					else tf-=3; 
				else{
					cout<<"NO"<<endl;
					return 0;
				}
				break;
			case 50:
				if(tf>=1){  //判断50能不能找
					ft++;
                    tf--;
				}
				else{
					cout<<"NO"<<endl;
					return 0;
				} 
				break;
			case 25:
				tf++;  //25不用找
				break;
		} 
    }
    cout<<"YES"<<endl;  //循环顺利结束说明全部都找齐了
    return 0;
}

碎觉~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值