博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 982B (优先队列)
阅读量:5237 次
发布时间:2019-06-14

本文共 3259 字,大约阅读时间需要 10 分钟。

题面:

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 (1n2000001≤n≤200000) — the number of rows in the bus.

The second line contains the sequence of integers w1,w2,,wnw1,w2,…,wn (1wi1091≤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
23 10011
output
Copy
2 1 1 2
input
Copy
610 8 9 11 13 5010010011101
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.

题目描述:

    有n行的椅子,每行有两个椅子,第i行的椅子的宽度为wi。

    第二行输入一个长度为2*n字符串,代表两种人,0表示第一种人,他们只会选择坐在一行没人的位子上,如果有多个地方满足条件,他会选择宽度最小的凳子;1表示第一种人,他们只会选择在坐在一行有一个人坐的位子上,如果有多个地方满足条件,则他们会优先选择宽度最大的凳子。询问这2*n个人分别坐在在哪一行。

题目分析:

    因为我们知道,1这类人一定是要坐在有一个人的地方的,因此,我们可以分析到,第一个坐下的必定是0的人。因为他们每次要坐在宽度最小的凳子上,因此我们在这里可以建立一个小根堆,每次遇到0的时候就将堆顶元素pop出;同时,因为这个人坐下后,导致了这个凳子可以被1这类人所坐,(而这类人要坐在宽度最大的凳子上)因此我们可以再建立一个大根堆,每次pop掉小根堆的元素后,将该元素再push进大根堆,当遇到1的时候再pop出大根堆堆顶元素即可。

代码:

#include 
#define maxn 200005using namespace std;typedef pair
PLL;int main(){ priority_queue
,greater
>que0; priority_queue
que1; int n; cin>>n; for(int i=1;i<=n;i++){ int tmp=0; cin>>tmp; que0.push(PLL(tmp,i)); } string str; cin>>str; int len=str.length(); for(int i=0;i

转载于:https://www.cnblogs.com/Chen-Jr/p/11007288.html

你可能感兴趣的文章
【BZOJ3052】【UOJ#58】【WC2013】糖果公园(树上莫队)
查看>>
荷兰国旗问题
查看>>
Process 启动参数问题
查看>>
提高PHP性能的10条建议
查看>>
我,不会吵,不会闹,心痛了用沉默代替
查看>>
svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法...
查看>>
项目经理面试中可能遇到的问题(持续更新)
查看>>
【转】总结前端面试过程中最容易出现的问题
查看>>
Java- 简单了解线程 生产者与消费者问题(三)
查看>>
centos rancher 通过本机 docker images 新增container
查看>>
【原】PNG的使用技巧
查看>>
android studio 使用SVN 锁定文件,防止别人修改(基于Android studio 1.4 )
查看>>
4412 uboot启动分析
查看>>
熟用TableView
查看>>
PHP动态页面 生产静态页 方法二
查看>>
Java大数——a^b + b^a
查看>>
poj 3164 最小树形图(朱刘算法)
查看>>
百度贴吧图片抓取工具
查看>>
服务器内存泄露 , 重启后恢复问题解决方案
查看>>
ajax post 传参
查看>>