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 ...
随机推荐
- Maven maven-compiler-plugin版本
项目执行Maven clean后出现WARNING提示.报如信息如下,根据报错信息 'build.plugins.plugin.version' for org.apache.maven.plugin ...
- eclipse创建的maven项目无法部署到tomcat
今天在eclipse中创建了个maven项目,想运行起来看看,发现代码开发完成后无法发布到tomcat. 解决办法如下: 第一种: 选中项目-右键属性-Project Facets 勾选上面三项并选择 ...
- C#设计模式(5)-建造者模式
引言 上一篇介绍了设计模式中的抽象工厂模式-C#设计模式(3)-抽象工厂模式,本篇将介绍建造者模式: 点击这里查看全部设计模式系列文章导航 建造者模式简介 建造者模式是将一个复杂对象的构建与表示分离, ...
- chrome开发工具指南(八)
编辑 DOM Chrome DevTools 的 Elements 面板中的 DOM 树视图可以显示当前网页的 DOM 结构.通过 DOM 更新实时修改页面的内容和结构. DOM 定义您的页面结构.每 ...
- 嵌套ajax 页面卡死的问题
问题:要一个AJAX中的回调函数中又进行了一个AJAX调用,并且这个AJAX是在一个循环调用的,不论设置async属性是true和false页面卡死. 解决方法:async属性都设为true,不用循环 ...
- 吐槽下微软的vs code编辑器
缺点:不能同时打开多个文件夹(打开多个文件夹得先ctrl+shift+N窗口或者除非你的所有项目文件都在同一个文件夹目录下) 优点是支持用户设置以及提供很多插件 // 将设置放入此文件中以覆盖默认设置 ...
- centos6 内核优化
以下为部分优化参数,具体优化方法还要看情况而定 [root@localhost ~]# vi /etc/sysctl.conf #末尾添加如下参数 net.ipv4.tcp_syncookie ...
- 【集美大学1411_助教博客】alpha阶段后 成绩
团队作业7 成绩(助教对团队排名) 团队名称 设想和目标 计划 资源 变更管理 设计/实现 测试/发布 团队的角色,管理,合作 总结 全组讨论的照片 团队成员在Alpha阶段的角色和具体贡献 合计 排 ...
- IT之光
作为一个IT界的新新人才,现在拥有第一个博客,可以在这里学习和分享IT方面的知识和技术.
- 团队作业4——第一次项目冲刺(Alpha版本)4.22
团队作业4--第一次项目冲刺(Alpha版本) Day one: 会议照片 由于团队中的组员今天不在学校,所以我们的站立会议提前一天展开. 项目进展 由于今天是Alpha版本项目冲刺的第一天,所以没有 ...