zoukankan      html  css  js  c++  java
  • Codeforces Round #414 A. Bank Robbery

    A. Bank Robbery
    time limit per test
      2 seconds
    memory limit per test  
    256 megabytes
     

    A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.

    Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the i-th safe from the left is called safe i. There are n banknotes left in all the safes in total. The i-th banknote is in safe xi. Oleg is now at safe a. There are two security guards, one of which guards the safe b such that b < a, i.e. the first guard is to the left of Oleg. The other guard guards the safe c so that c > a, i.e. he is to the right of Oleg.

    The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather.

    Input

    The first line of input contains three space-separated integers, ab and c (1 ≤ b < a < c ≤ 109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.

    The next line of input contains a single integer n (1 ≤ n ≤ 105), denoting the number of banknotes.

    The next line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109), denoting that the i-th banknote is located in thexi-th safe. Note that xi are not guaranteed to be distinct.

    Output

    Output a single integer: the maximum number of banknotes Oleg can take.

     
    input
    5 3 7
    8
    4 7 5 5 3 6 2 8
    output
    4
    input
    6 5 7
    5
    1 5 7 92 3
    output
    0
    Note:

    In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes.

    For the second sample, Oleg can't take any banknotes without bumping into any of the security guards.

    题目大意:

          有一个小偷想去偷银行的钱,他打听到银行一共有n个保险箱在一条直线上给出每个保险箱的位置

         (每一个位置上不一定只有一个保险箱)

         小偷现在在a,有两个保安他们分别在b和c处(a > b   a < c) 两个保安特别懒他们保持不动

         小偷不能越过保安去偷钱,问小偷可以偷多少个保险箱

    解题思路:

         可能是时间长不敲代码了吧。被这么水的题困了半天。

         输入一个位置只要判断当前位置是否在两个保安的位置之间,是+1 然后输出即可(真是被自己蠢到了)

    AC代码:

     1 #include<stdio.h>
     2 int main ()
     3 {
     4     int a,b,c,i,n,p,sum;
     5     while (~scanf("%d%d%d",&a,&b,&c))
     6     {
     7         scanf("%d",&n); sum = 0;
     8         for (i = 0; i < n; i ++)
     9         {
    10             scanf("%d",&p);
    11             if (p > b && p < c)
    12                 sum ++;
    13         }
    14         printf("%d
    ",sum);
    15     }
    16     return 0;
    17 }
  • 相关阅读:
    xgboost系列之应用xgboost的注意事项
    【pandas】pandas.DataFrame.rename()---重置索引名称
    【剑指offer】复杂链表的复制
    【剑指offer】二叉树中和为某一值的路径,C++实现
    设计模式21 访问者模式
    设计模式20 迭代器模式
    设计模式19 中介者模式
    设计模式18 观察者模式
    设计模式17 状态模式
    设计模式16 责任链模式
  • 原文地址:https://www.cnblogs.com/yoke/p/6869303.html
Copyright © 2011-2022 走看看