refresh的停车场 分类: 栈和队列 2015-06-18 17:13 26人阅读 评论(0) 收藏
refresh的停车场
TimeLimit: 1000ms Memory limit: 65536K
题目描述
refresh最近发了一笔横财,开了一家停车场。由于土地有限,停车场内停车数量有限,但是要求进停车场的车辆过多。当停车场满时,要进入的车辆会进入便道等待,最先进入便道的车辆会优先
进入停车场,而且停车场的结构要求只出去的车辆必须是停车场中最后进去的车辆。现告诉你停车场容量N以及命令数M,以及一些命令(Addnum
表示车牌号为num的车辆要进入停车场或便道,
Del表示停车场中出去了一辆车,Out表示便道最前面的车辆不再等待,放弃进入停车场)。假设便道内的车辆不超过1000000.
输入
输入为多组数据,每组数据首先输入N和M(0< n,m <200000),接下来输入M条命令。
输出
输入结束后,如果出现停车场内无车辆而出现Del或者便道内无车辆而出现Out,则输出Error,否则输出停车场内的车辆,最后进入的最先输出,无车辆不输出。
示例输入
26
Add18353364208
Add18353365550
Add18353365558
Add18353365559
Del
Out
示例输出
18353365558
18353364208
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <time.h>
#include <cstdio>
#include <cctype>
#include <vector>
#include <string>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
#define INF 0x3f3f3f3f using namespace std; int main()
{
int n,m;
int ans;
string con;
string num;
while(~scanf("%d %d",&n,&m))
{
stack<string>park;
queue<string>street;
ans=0;
bool flag=true;
for(int i=0;i<m;i++)
{
cin>>con;
if(con=="Add")
{
cin>>num;
if(ans<n)
{
park.push(num);
ans++;
}
else
{
street.push(num);
}
}
else if(con=="Del")
{
if(!park.empty())
{
park.pop();
ans--;
}
else
{
flag=false;
}
if(!street.empty()&&ans<n)//经入停车场
{
num=street.front();
street.pop();
park.push(num);
ans++;
}
}
else if(con=="Out")
{
if(!street.empty())
{
street.pop();
}
else
{
flag=false;
}
}
}
if(!flag)
{
cout<<"Error"<<endl;
}
else
{
while(!park.empty())
{
cout<<park.top()<<endl;
park.pop();
}
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
refresh的停车场 分类: 栈和队列 2015-06-18 17:13 26人阅读 评论(0) 收藏的更多相关文章
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- hdu 1232, disjoint set, linked list vs. rooted tree, a minor but substantial optimization for path c 分类: hdoj 2015-07-16 17:13 116人阅读 评论(0) 收藏
three version are provided. disjoint set, linked list version with weighted-union heuristic, rooted ...
- Ubiquitous Religions 分类: POJ 2015-06-16 17:13 11人阅读 评论(0) 收藏
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 26678 Accepted: ...
- hdu 1031 (partial sort problem, nth_element, stable_partition, lambda expression) 分类: hdoj 2015-06-15 17:47 26人阅读 评论(0) 收藏
partial sort. first use std::nth_element to find pivot, then use std::stable_partition with the pivo ...
- OC基础知识总结 分类: ios学习 OC 2015-06-26 17:58 58人阅读 评论(0) 收藏
//OC: Objective-C, 面向对象的C语言 //OC与C的区别 //1.OC是C的超集, C语言的所有语法都可以在OC中使用 //2.OC是面向对象 //3.OC是一门运行时语言 //4. ...
- Get the current user permission level on a list item with ecmascript 分类: Sharepoint 2015-07-14 14:13 7人阅读 评论(0) 收藏
To Check current users permissions using Ecmascript\Javascript client object model SharePoint 2010. ...
- jQuery easyUI datagrid 增加求和统计行 分类: JavaScript 2015-01-14 17:46 2178人阅读 评论(0) 收藏
在datagrid的onLoadSuccess事件增加代码处理. <style type="text/css"> .subtotal { font-weight: bo ...
- OpenMP对于嵌套循环应该添加多少个parallel for 分类: OpenMP C/C++ Linux 2015-04-27 14:48 53人阅读 评论(0) 收藏
一个原则是:应该尽量少的使用parallelfor, 因为parallel for也需要时间开销.即: (1)如果外层循环次数远远小于内层循环次数,内层循环较多时,将parallel for加在内层循 ...
- Shuffle'm Up 分类: 函数 POJ 查找 2015-08-09 17:01 6人阅读 评论(0) 收藏
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7529 Accepted: 3466 Descript ...
随机推荐
- G面经prepare: Android Phone Unlock Pattern
1 2 3 4 5 6 7 8 9 只有中间没有其他键的两个键才能相连,比如1可以连 2 4 5 6 8 但不能连 3 7 9 但是如果中间键被使用了,那就可以连,比如5已经被使用了,那1就可以连9 ...
- C++builder 图像字符流的存储和加载
__fastcall TForm6::TForm6(TComponent* Owner) : TForm(Owner) { #if 1 //for debug AllocConsole(); Atta ...
- 数据可视化工具zeppelin安装
介绍 zeppelin主要有以下功能 数据提取 数据发现 数据分析 数据可视化 目前版本(0.5-0.6)之前支持的数据搜索引擎有如下 安装 环境 centOS 6.6 编译准备工作 sudo yum ...
- Uploadify在MVC中使用方法案例(一个视图多次上传单张图片)
Controller 中代码和 上一节文章(http://www.cnblogs.com/yechangzhong-826217795/p/3785842.html )一样 视图中代码如下: < ...
- Jqueryの锋利的jquery练习
$(function(){ $("div.SubCategoryBox li:gt(7):not(:last)").hide(); $("div.SubCategoryB ...
- 夺命雷公狗mongodb之----mongodb---1---的下载,安装,连接
首先登录mongodb的官方网站即可进行下载: https://www.mongodb.com/download-center?jmp=nav#community 然后到wamp目录下创建一个mong ...
- 夺命雷公狗ThinkPHP项目之----企业网站17之网站配置页的添加
为了网站可以智能一点,所以我们开始来写一个网站配置的功能.. 所以我来写他的数据表: 先来完成他的添加功能,页面效果如下所示: lists.html代码如下所示: <!doctype html& ...
- Logic Bist Arch
一般现在多用的都是offline BIST的架构,可以分为4大类: 1)those assume no special structure to the circuit under test; 2)t ...
- 清华大学出版社即将推出的又一本挂羊头卖狗肉的劣书 《C语言入门1.2.3—一个老鸟的C语言学习心得》
http://www.tup.com.cn/book/showbook.asp?CPBH=051892-01
- Attribute 与 Property 的区别
网上的说法是: Property 是面向对象的概念,是Object的一部分. Attribute 是<input type="text"> type就是Attribut ...