题意:一家有10间房间的旅馆(10个房间排成一排),在旅馆的左右两端都有一个办理入住的前台,L代表在左端办理入住,R代表在右端办理入住,顾客都会挑选距离最近的空房间入住,数字 i 表示房间号为   i  的顾客退房,问最后房间的入住情况
 
题解:用set保存每个空房间的房间号(房间号从0开始),然后每次对set的两端进行操作
 
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<utility>
#include<map>
#include<queue>
#include<set>
#define mx 0x3f3f3f3f
#define ll long long
using namespace std;
int a[];
string s;
set<int>p;
int main()
{
int n,l=,r=,pos=-;
cin>>n;
for(int i=;i<;i++)
p.insert(i);
cin>>s;
for(int i=;s[i];i++)
{
if(s[i]=='L')
{
int temp=*(p.begin());
a[temp]=;
p.erase(p.begin());
}
else if(s[i]=='R')
{
int temp=*(p.rbegin());
a[temp]=;
set<int>::iterator it=p.end();
p.erase(--it);
}
else
{
a[s[i]-'']=;
p.insert(s[i]-'');
}
}
for(int i=;i<;i++)
cout<<a[i];
cout<<endl;
return ;
}

A. Hotelier的更多相关文章

  1. 【CodeForces - 1200A】Hotelier(水题、模拟)

    Hotelier 直接翻译了 Descriptions Amugae的酒店由10人组成10客房.房间从0开始编号0到99 从左到右. 酒店有两个入口 - 一个来自左端,另一个来自右端.当顾客通过左入口 ...

  2. 【cf补题记录】A. Hotelier

    思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Hotelier 题意 给出长度为n的字符串,字符串由'L'.'R'以及数字0~9组成.旅馆有10间房子,L代表客人从左边入住,R代表客人从右边入 ...

  3. python设计模式---结构型之门面模式

    门面,系统,客户端~ from django.test import TestCase class Hotelier: def __init__(self): print('Arranging the ...

  4. Cassandra 学习三 数据模型

       Cassandra如何存储数据的概述. 集群(Cluster) ·Cassandra数据库分布在几个一起操作的机器上.最外层容器被称为集群.对于故障处理,每个节点包含一个副本,如果发生故障,副本 ...

  5. Codeforces Round #578 (Div. 2)

    Codeforces Round #578 (Div. 2) 传送门 A. Hotelier 暴力即可. Code #include <bits/stdc++.h> using names ...

  6. codeforces #578(Div.2)

    codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...

  7. Codeforces Round #578 (Div. 2) Solution

    Problem A Hotelier 直接模拟即可~~ 复杂度是$O(10 \times n)$ # include<bits/stdc++.h> using namespace std; ...

  8. CF #578 Div2

    // 比赛链接:https://codeforces.com/contest/1200 A - Hotelier 题意: 有一家旅馆有10间房,编号0~9,从左到右顺序排列.旅馆有左右两扇门,每次新来 ...

随机推荐

  1. Vue项目中sass语法该怎么用?

    最近开始着手Vue框架,被各种报错蹂躏,其中有一个就是sass语法,<style>标签中添加<style lang="scss">,发现报错,在网上找了一些 ...

  2. 定义列表dl中标签 dt 与标签dd对齐方法,标签ul与标签li对齐

    不定义css样式时(默认情况): 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  3. window.onresize

    $(function() { window.onresize = function() { alert("abc"); }; window.onresize = function( ...

  4. Vue-全局变量和方法

    一.单文件引入 1.创建存放全局变量和方法的vue文件 Common.uve <script> const userName = 'yangjing'; function add(a,b) ...

  5. 如何在应用程序中使用ML.NET?

    https://www.cnblogs.com/shanyou/p/9190701.html ML.NET以NuGet包的形式提供,可以轻松安装到新的或现有的.NET应用程序中. 该框架采用了用于其他 ...

  6. 计算机基础 - 动态规划、分治法、memo

    动态规划 ≈ 分治法 + memo def memo(func): cache = {} def wrap(*args): if args not in cache: cache[args] = fu ...

  7. Unity2018编辑器脚本趟坑记录

    解除预制体问题:(这个例子是解除游戏中的Canvas与Asset中的预制体的关系) if( PrefabUtility.IsAnyPrefabInstanceRoot(GameObject.Find( ...

  8. 给服务添加路由--ingress

    kind: NamespaceapiVersion: v1metadata:  name: demo-webshell  generateName: demo-webshell  labels:    ...

  9. Educational Codeforces Round 77 (Rated for Div. 2) - D. A Game with Traps(二分)

    题意:$m$个士兵,每个士兵都有一个灵敏度$a[i]$,起点为$0$,终点为$n + 1$,在路上有$k$个陷阱,每个陷阱有三个属性$l[i],r[i],d[i]$,$l[i]$表示陷阱的位置,如果你 ...

  10. Update(Stage4):Spark Streaming原理_运行过程_高级特性

    Spark Streaming 导读 介绍 入门 原理 操作 Table of Contents 1. Spark Streaming 介绍 2. Spark Streaming 入门 2. 原理 3 ...