http://codeforces.com/contest/349
2 seconds
256 megabytes
standard input
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?
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.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
4
25 25 50 50
YES
2
25 100
NO
4
50 50 25 25
NO
简介:买电影票一张25一张,然后营业员最初没有钱,给你一个只有25 ,50,100的数列,问能否成功卖票,成功输出“yes”否则输出“NO”
题解:直接模拟,x代表25的票数y代表50的票数z代表100的票数
代码如下:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=1e5+;
int a[maxn];
int x,y,z,n;
int main()
{
scanf("%d",&n);
int flag=true;
x=y=z=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
if(flag)
{
if(a[i]==)
{
x++;
}
else if(a[i]==)
{
y++;
if(x>=)
{
x--;
}
else
{
flag=false;
}
}
else
{
z++;
if(y>=&&x>=)
{
y--;
x--;
}
else if(x>=)
{
x=x-;
}
else
{
flag=false;
}
} } }
if(flag)
{
cout<<"YES\n";
}
else
{
cout<<"NO\n";
}
}
题目连接http://codeforces.com/contest/349/problem/A
http://codeforces.com/contest/349的更多相关文章
- codeforces 725D . Contest Balloons(贪心+优先队列)
题目链接:codeforces 725D . Contest Balloons 先按气球数从大到小排序求出初始名次,并把名次排在第一队前面的队放入优先队列,按w-t-1值从小到大优先,然后依次给气球给 ...
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- CodeForces - 725D Contest Balloons 贪心
D. Contest Balloons time limit per test 3 seconds memory limit per test 2 ...
- http://codeforces.com/contest/555/problem/B
比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...
- http://codeforces.com/contest/845
A. Chess Tourney time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- http://codeforces.com/contest/610/problem/D
D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- http://codeforces.com/contest/536/problem/B
B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/535/problem/C
C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 基于moco的mock server 简单应用 来玩玩吧
提起mock大家应该就知道是干嘛用的了,再次再介绍一种简单的方式,基于moco的mock server.步骤很简单: 1. 首先,要下载个moco的jar0_1482402640757_moco-ru ...
- Spark Mllib框架1
1. 概述 1.1 功能 MLlib是Spark的机器学习(machine learing)库,其目标是使得机器学习的使用更加方便和简单,其具有如下功能: ML算法:常用的学习算法,包括分类.回归.聚 ...
- vue系列之动态路由【原创】
开题 最近用vue来构建了一个小项目,由于项目是以iframe的形式嵌套在别的项目中的,所以对于登录的验证就比较的麻烦,索性后端大佬们基于现在的问题提出了解决的方案,在看到他们的解决方案之前,我先画了 ...
- 浅谈如何用Java操作MongoDB
NoSQL数据库因其可扩展性使其变得越来越流行,利用NoSQL数据库可以给你带来更多的好处,MongoDB是一个用C++编写的可度可扩展性的开源NoSQL数据库.本文主要讲述如何使用Java操作Mon ...
- Project 4:Longest Ordered Subsequence
Problem description A numeric sequence of ai is ordered if a1 < a2 < - < aN. Let the subseq ...
- 团队作业4——第一次项目冲刺 FiRsT DaY
项目冲刺--first blood 今天是阳光明媚的一天[明明是阴天好吗= =],今天是心情愉悦的一天[每天都要提交博客高兴个水水哦-3-] 天霸动霸.tua小队迎来了第一敏捷冲刺,小伙伴们是时候打起 ...
- 201521123005 《java程序设计》 第二周学习总结
1. 本周学习总结 ·java中的字符串及String的用法 "=="比较的是两字符串的地址,而不是内容 String类的对象是不可变的,创建之后不能进行修改 ·数组Array的用 ...
- Java课程设计-随机密码生成器
1.团队课程设计博客链接 团队课程设计博客地址 2.个人负责模板 随即密码生成器算法 3.自己的代码提交记录截图 4.自己负责模块或任务详细说明 负责随机密码算法设计实现 通过不同种类选择下生成密码, ...
- 201521123025<<java程序设计>>第9周学习总结
1. 本周学习总结 2.书面作业 Q1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 经常出现Array ...
- 一个Markdown的例子
一个例子: 例子开始 1. 本章学习总结 今天主要学习了三个知识点 封装 继承 多态 2. 书面作业 Q1. java HelloWorld命令中,HelloWorld这个参数是什么含义? 今天学了一 ...