原博主: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();
}

Codeforces Round #484 (Div. 2) B. Bus of Characters(STL+贪心)982B的更多相关文章

  1. Codeforces Codeforces Round #484 (Div. 2) E. Billiard

    Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/proble ...

  2. Codeforces Codeforces Round #484 (Div. 2) D. Shark

    Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D ...

  3. Codeforces Round #484 (Div. 2)

    题目链接:http://codeforces.com/contest/982 A. Row time limit per test:1 second memory limit per test:256 ...

  4. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. Codeforces Round #436 (Div. 2)C. Bus 模拟

    C. Bus time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input out ...

  6. Codeforces Round #369 (Div. 2) A. Bus to Udayland 水题

    A. Bus to Udayland 题目连接: http://www.codeforces.com/contest/711/problem/A Description ZS the Coder an ...

  7. Codeforces Round #369 (Div. 2) A. Bus to Udayland (水题)

    Bus to Udayland 题目链接: http://codeforces.com/contest/711/problem/A Description ZS the Coder and Chris ...

  8. Codeforces Round #436 (Div. 2) C. Bus

    http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a ...

  9. Codeforces Round #491 (Div. 2) E - Bus Number + 反思

    E - Bus Number 最近感觉打CF各种车祸.....感觉要反思一下, 上次读错题,这次想当然地以为18!肯定暴了longlong 而没有去实践, 这个题我看到就感觉是枚举每个数字的个数,但是 ...

随机推荐

  1. MapReduce 编程模型 & WordCount 示例

    学习大数据接触到的第一个编程思想 MapReduce.   前言 之前在学习大数据的时候,很多东西很零散的做了一些笔记,但是都没有好好去整理它们,这篇文章也是对之前的笔记的整理,或者叫输出吧.一来是加 ...

  2. C++单继承、多继承情况下的虚函数表分析

    C++的三大特性之一的多态是基于虚函数实现的,而大部分编译器是采用虚函数表来实现虚函数,虚函数表(VTAB)存在于可执行文件的只读数据段中,指向VTAB的虚表指针(VPTR)是包含在类的每一个实例当中 ...

  3. 第十章 Fisco Bcos 权限控制下的数据上链实操演练

    一.目的 前面已经完成fisco bcos 相关底层搭建.sdk使用.控制台.webase中间件平台等系列实战开发, 本次进行最后一个部分,体系化管理区块链底层,建立有序的底层控管制度,实现权限化管理 ...

  4. 夯实Java基础(十二)——异常处理

    1.异常处理概述 在Java程序执行过程中, 总是会发生不被期望的事件, 阻止程序按照程序员预期正常运行, 这就是Java程序出现的异常. 异常处理是基于面向对象的一种运行错误处理机制,通过对异常问题 ...

  5. 佳木斯集训Day4

    Day4的出题人好毒瘤啊!!! T1我打表过的,正解现在也不会 #include <bits/stdc++.h> #define MAXN 10050 #define ll long lo ...

  6. 【Java例题】2.7找零钱

    7.为顾客找零钱时,希望选用的纸币张数最少. 例如73元,希望零钱的面值为五十元1张,二十元1张,一元3张. 设零钱面值有五十元.二十元.十元.五元和一元, 请编写程序,用户输入100以下的数, 计算 ...

  7. AWS Aurora数据库 Multi-Master 小测

    AWS Aurora Mysql终于推出了Multi-Master,直面硬刚Oracle RAC.在多一份数据库产品选择的小兴奋之余,我们也看看新推出的Multi-Master的特点(包括优缺点). ...

  8. 7、数组中添加元素(test5.java)

    前文提到了系统函数,arraycopy(),这是一个强大的函数,根据它的特性便可以看出由于他的特殊性质,加以利用的话,就在数组中添加元素,但这样的方式会造成的结果就是,添加n个元素,那么原数组中倒数n ...

  9. Go中的interface学习

    学过Java的同学都知道在Java中接口更像是一种规范,用接口定义了一组方法,下面实现这个接口的类只管按照写好的方法名和返回值去实现就好,内部如何实现是各个方法自己的事情,接口本身不关注. 另外Jav ...

  10. UML类图(1.3)

    UML:Unified modeling Language 统一建模语言 UML类图:用来描述系统所包含的类以及类之间的关系. 画图工具:https://www.processon.com 类之间的6 ...