• http://codeforces.com/contest/349


    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
    "; 
    58     } 
    59     else
    60     {
    61         cout<<"NO
    "; 
    62     } 
    63 } 

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

  • 相关阅读:
    .Net和SqlServer的事务处理实例
    SQL Server-- 存储过程中错误处理
    Asp.Net中使用Newtonsoft.Json转换,读取,写入
    从客户端中检测到有潜在危险的 Request.Form 值
    -Json与Xml之间的转换
    c#操作xml的代码(插入节点、修改节点、删除节点等)
    重置SQL Server sa密码
    用exec调用带有output输出参数的存储过程
    日期获取 net
    PhoneListenerService
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/7142383.html
Copyright © 2020-2023  润新知