http://codeforces.com/contest/349
Posted lhclqslove
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了http://codeforces.com/contest/349相关的知识,希望对你有一定的参考价值。
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的票数
代码如下:
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
以上是关于http://codeforces.com/contest/349的主要内容,如果未能解决你的问题,请参考以下文章