原博主:https://blog.csdn.net/amovement/article/details/80358962
B. Bus of Characters
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In the Bus of Characters there are nn rows of seat, each having 22 seats. The width of both seats in the ii-th row is wiwi centimeters. All integers wiwi are distinct.

Initially the bus is empty. On each of 2n2n stops one passenger enters the bus. There are two types of passengers:

  • an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;
  • an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.

You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.

Input

The first line contains a single integer nn (1≤n≤2000001≤n≤200000) — the number of rows in the bus.

The second line contains the sequence of integers w1,w2,…,wnw1,w2,…,wn (1≤wi≤1091≤wi≤109), where wiwi is the width of each of the seats in the ii-th row. It is guaranteed that all wiwi are distinct.

The third line contains a string of length 2n2n, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the jj-th character is '0', then the passenger that enters the bus on the jj-th stop is an introvert. If the jj-th character is '1', the the passenger that enters the bus on the jj-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal nn), and for each extrovert there always is a suitable row.

Output

Print 2n2n integers — the rows the passengers will take. The order of passengers should be the same as in input.

Examples
input

Copy
2
3 1
0011
output

Copy
2 1 1 2
input

Copy
6
10 8 9 11 13 5
010010011101
output

Copy
6 6 2 3 3 1 4 4 1 2 5 5
Note

In the first example the first passenger (introvert) chooses the row 22, because it has the seats with smallest width. The second passenger (introvert) chooses the row 11, because it is the only empty row now. The third passenger (extrovert) chooses the row 11, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row 22, because it is the only row with an empty place.

一、原题地址

http://codeforces.com/contest/982/problem/B

二、大致题意

一辆公交有n排座位,每排座位有两个椅子。

接着给出每排座位的宽度。

这时有2*n个人要上车,这群人有两种类型。

1、内向的人:会优先选择座位宽度最小的那排就坐,最好旁边是没人的。

2、外向的人:会优先选择座位旁边有人的那排就坐,在此基础上座位选择越大越好。

三、思路

我们可以先把座位的宽度进行排序。

1、当内向的人上车时,我们记录一个pos表示当前内向的人最优的位置,同时将座位的编号存入栈。

2、当外向的人上车时,我们提取栈内最顶端的元素,因为内向的人是按照座位宽度从小到大入座的,所以此时的栈顶元素,必定为有内向的人就坐的宽度最大的位置。同时删除栈顶元素,表示这个位置被使用了。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int inf = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return a == ? b : gcd(b % a, a); } int n;
struct SEAT
{
int w, id;
}seat[];
bool cmp(SEAT xx, SEAT yy)
{
return xx.w < yy.w;
}
int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%d", &seat[i].w);
seat[i].id = i;
}
sort(seat + , seat + + n, cmp);
char s[ * ];
scanf("%s", s);
int pos0 = ;
stack<int>sta;
for (int i = ; i < * n; i++)
{
if (s[i] == '')
{
printf("%d ", seat[pos0].id);
sta.push(seat[pos0].id);
pos0++;
}
else if (s[i] == '')
{
printf("%d ", sta.top());
sta.pop();
}
}
getchar();
getchar();
}

最新文章

  1. p2p网贷系统即将上线
  2. MS SQL 两种分页
  3. php 二维数组排序,多维数组排序
  4. CentOS安装Erlang
  5. webform中的Eval的使用
  6. oc中对象的初始化
  7. js之json
  8. 03 InnoDB锁问题
  9. .net面试问答(大汇总)
  10. Oracle树反向查询的优化(转载)
  11. 移植iw 到linux平台上。
  12. python+selenium自动化软件测试(第4章):场景判断与封装
  13. java.util.Arrays.useLegacyMergeSort=true 作用
  14. XII Open Cup named after E.V. Pankratiev. GP of Eastern Europe (AMPPZ-2012)
  15. H.264学习--1
  16. Flutter之 LimitedBox、Offstage、OverflowBox、SizedBox详解
  17. GRNN/PNN:基于GRNN、PNN两神经网络实现并比较鸢尾花种类识别正确率、各个模型运行时间对比—Jason niu
  18. obs studio 使用
  19. eclipse中tomcat无法加载spring boot
  20. ElasticSearch 2 (33) - 信息聚合系列之聚合过滤

热门文章

  1. win10教育版激活错误:在运行 Microsoft Windows 非核心版本的计算机上,运行&quot;slui.exe ...”
  2. Redis总结(八)如何搭建高可用的Redis集群
  3. IDED中配置SVN没有svn.exe解决办法
  4. python异常处理-异常捕获-抛出异常-断言-自定义异常-UDP通信-socketserver模块应用-3
  5. todaytt
  6. stm8s和stm8l低功耗对比
  7. 使用Prerender.io进行网站预加载
  8. 以股票案例入门基于SVM的机器学习
  9. mysql数据库的水平拆分与垂直拆分
  10. Linux下Tomcat的搭建以及开机自启动设置