codeforce A. Bank Robbery
来源:互联网 发布:mac如何卸载梦幻西游 编辑:程序博客网 时间:2024/06/03 15:43
题目链接:点击打开链接
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.
The first line of input contains three space-separated integers, a, b 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 a single integer: the maximum number of banknotes Oleg can take.
5 3 784 7 5 5 3 6 2 8
4
6 5 751 5 7 92 3
0
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.
水题,英语不好,我的理解是 给你三个人的位置,Oleg的位置,守卫一,守卫二的位置,给你所有支票的数量以及位置,求在不遇到守卫的情况下,这个人能带走多少支票,水题啊,暴力解决,在守卫一和守卫二的区间内,求出支票的数量,也就是说,如果支票的位置小于等于第一个守卫或大于等于第二个就没法带走。
代码实现:
#include<iostream>#include<algorithm>using namespace std;int main(){long long a,b,c,map[100005],i,j,k,n;while(cin>>a>>b>>c){long long sum=0;cin>>n;for(i=0;i<n;i++){cin>>map[i];}for(i=0;i<n;i++){if(map[i]>b&&map[i]<c)sum++;}cout<<sum<<endl;}return 0;}
- codeforce A. Bank Robbery
- CodeForce 89A.Robbery
- 小白题解 Codeforces 794A Bank Robbery
- 0526 CF#794A&G2n E- Bank Robbery
- Codeforces Round #414, rated, Div. 1 + Div. 2 A. Bank Robbery
- 小偷分赃 等比求和 CodeChef Bank robbery
- LightOJ 1163 - Bank Robbery (思维方程式求解)
- Codeforce A
- codeforce 796C Bank Hacking 智力题orz
- codeforces 601E. A Museum Robbery
- Codeforce # A Plug-in
- codeforce 2A Winner
- Contest on codeforce A
- codeforce 11 04 A
- codeforce小水题--A. Presents
- Codeforce #145A Cinema
- codeforce日记 371A
- CodeForce 393A Nineteen
- 移动端数据库神器-Realm 项目配置(入门一)
- 剑指Offer(第二版)面试题9:用两个栈实现队列
- 【机器学习实战-python3】利用SVD简化数据
- C++中指针和引用的异同
- java--十进制转化为二进制、十进制转化为十六进制、查表法十进制--十六进制、查表法十进制二进制、
- codeforce A. Bank Robbery
- 多线程之读写锁
- Android studio——启动时禁止更新
- 文件服务器—NFS
- 知识总结5.14
- 哈希表——概念
- Jar包冲突解决方法 Unknown lifecycle phase "mvn" Eclipse中执行maven命令
- Error: Failed to synchronize cache for repo 'fedora'
- P1034 矩形覆盖