A. Hotelier
Problem
Amugae has a hotel consisting of rooms. The rooms are numbered from to from left to right.
The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.
One day, Amugae lost the room assignment list. Thankfully Amugae’s memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae’s memory.
Input
The first line consists of an integer , the number of events in Amugae’s memory.
The second line consists of a string of length describing the events in chronological order. Each character represents:
‘L’: A customer arrives from the left entrance.
‘R’: A customer arrives from the right entrance.
‘0’, ‘1’, …, ‘9’: The customer in room x (0, 1, …, 9 respectively) leaves.
It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room when is given. Also, all the rooms are initially empty.
Output
In the only line, output the hotel room’s assignment status, from room to room . Represent an empty room as ‘0’, and an occupied room as ‘1’, without spaces.
Examples
input
8
LLRL1RL1
output
1010000011
input
9
L0L0LLRR9
output
1100000010
Note
In the first example, hotel room’s assignment status after each action is as follows.
·First of all, all rooms are empty. Assignment status is 0000000000.
·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
·L: one more customer from the left entrance. Assignment status is 1100000000.
·R: one more customer from the right entrance. Assignment status is 1100000001.
·L: one more customer from the left entrance. Assignment status is 1110000001.
·1: the customer in room 1 leaves. Assignment status is 1010000001.
·R: one more customer from the right entrance. Assignment status is 1010000011.
·L: one more customer from the left entrance. Assignment status is 1110000011.
·1: the customer in room 1 leaves. Assignment status is 1010000011.
So after all, hotel room’s final assignment status is 1010000011.
In the second example, hotel room’s assignment status after each action is as follows.
·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
·0: the customer in room 0 leaves. Assignment status is 0000000000.
·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again.
·0: the customer in room 0 leaves. Assignment status is 0000000000.
·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
·L: one more customer from the left entrance. Assignment status is 1100000000.
·R: one more customer from the right entrance. Assignment status is 1100000001.
·R: one more customer from the right entrance. Assignment status is 1100000011.
·9: the customer in room 9 leaves. Assignment status is 1100000010.
So after all, hotel room’s final assignment status is 1100000010.
想法
暴力出奇迹
The Code Of My Program
/*********************
*@Author: ChenShou *
*@Language: C++11 *
*********************/
//#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3f3f3f3f;
inline ll read(){
long long x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int n;
int room [15]={0};
char op[100005];
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//cout.tie(0);
//scanf("%d",&t);
//while(t--){
//}
n=read();
scanf("%s",op);
for(int i=0;i<n;i++){
if(op[i]=='L'){
for(int j=0;j<=9;j++){
if(!room[j]){
room[j]=1;
break;
}
}
}else
if(op[i]=='R'){
for(int j=9;j>=0;j--){
if(!room[j]){
room[j]=1;
break;
}
}
}
else {
int now=op[i]-'0';
room[now]=0;
}
}
for(int i=0;i<10;i++){
printf("%d",room[i]);
}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Fuck You !" << endl;
return 0;
}
来源:https://blog.csdn.net/J_K_ang/article/details/99291934