URAL 1787 Turn for MEGA (贪心 + 模拟)
来源:互联网 发布:有人使用中文域名吗 编辑:程序博客网 时间:2024/05/25 16:37
Turn for MEGA
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
A traffic light at the turn for the “MEGA” shopping center from the Novomoskovskiy highway works in such a way that k cars are able to take a turn in one minute. At weekends all the residents of the city drive to the mall to take a shopping, which results in a huge traffic jam at the turn. Administration of the mall ordered to install a camera at the nearby bridge, which is able to calculate the number of cars approaching this turn from the city. The observation started n minutes ago. You should use the data from the camera to determine the number of cars currently standing in the traffic jam.
Input
The first line contains integers k and n (1 ≤ k, n ≤ 100), which are the number of cars that can take a turn to “MEGA” in one minute and the number of minutes passed from the beginning of observation. The second line contains space-separated integers a1, …, an (0 ≤ ai ≤ 100), where aiis the number of cars that approached the turn during the i-th minute. The observation started at morning, when there were no cars at the turn.
Output
Output the number of cars currently standing in the traffic jam.
Samples
5 36 7 2
0
5 320 0 0
5
题意:一个路口,可以同时允许k辆车调头,已知n分钟内到达该路口的车辆,问此时还有多少车辆堵在路上不能调头。
解析:按实际的情况模拟即可。该分钟没有通过的车辆,会堵在路口等待下分钟通行,但是即使该分钟通过的车辆不足k,下一分钟还没有来的车辆也不能补上!!!
AC代码:
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif //sxk int k, n, car; while(cin>>k>>n){ int ans = 0; //当前未通过的车辆 for(int i=0; i<n; i++){ cin>>car; if(ans + car > k) ans += car - k; //不能完全通过 else ans = 0; } cout<<ans<<endl; } return 0;}
0 0
- URAL 1787 Turn for MEGA (贪心 + 模拟)
- Ural 1787. Turn for MEGA
- URAL 1787. Turn for MEGA
- Timus 1787. Turn for MEGA 题解
- URAL 1820 Ural Steaks (贪心)
- URAL 2041 Nanomatryoshkas(贪心)
- POJ 3106Flip and Turn(模拟)
- acdream 1043 Always Turn Left(模拟)
- URAL 1319. Hotel (模拟)
- URAL 1964 - Chinese Dialects(贪心)
- URAL 1203 Scientific Conference(贪心 || DP)
- Ural 1303 Minimal Coverage(贪心)
- URAL 2021 Scarily interesting!(贪心)
- URAL 1876. Centipede's Morning (贪心)
- URAL 1025. Democracy in Danger (贪心)
- Ural 1303 Minimal Coverage(贪心)
- URAL 1762 Search for a Hiding-Place(数学·模拟)
- ural 1820. Ural Steaks 贪心
- 数据库的操作笔记
- Cocos2d策略类塔防精品手游-MiniTD独家完整源码
- 为什么c++中函数指针是16字节
- 简单讨论操作系统的工作机制
- MVC,MVP 和 MVVM 的图示
- URAL 1787 Turn for MEGA (贪心 + 模拟)
- Codeforces 520D. Cubes 贪心模拟
- 数据缓存NSURLCache
- uva 507 Jill Rides Again (分治)
- session超时设置
- 黑马程序员__内部类及其应用
- UVA 1625 Color Length (DP)
- network: Android 网络判断(wifi、3G与其他)
- Jquery Table 的基本操作