Codeforces 982 B. Bus of Characters(模拟一个栈)
解题思路:
排序之后模拟一个栈(也可以用真的栈),时间复杂度o(n)。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; struct node{
int val;int idx;
}w[];
bool cmp(node x, node y){
return x.val < y.val;
} char a[];
stack <node> s;
int main(){
int n;
scanf("%d", &n);
for(int i = ;i <= n; i++) scanf("%d", &w[i].val),w[i].idx = i;
sort(w+, w++n, cmp);
scanf("%s", a+);
node l;
int j = ;
for(int i = ;i <= *n; i++){
if(a[i] == ''){
s.push(w[j++]);
printf("%d ",w[j-].idx);
}else{
l = s.top();
printf("%d ",l.idx);
s.pop();
}
}
return ;
}
Codeforces 982 B. Bus of Characters(模拟一个栈)的更多相关文章
- 两队列模拟一个栈,python实现
python实现两个队列模拟一个栈: class Queue(object): def __init__(self): self.stack1=[] self.stack2=[] def enqueu ...
- Codeforces Round #484 (Div. 2) B. Bus of Characters(STL+贪心)982B
原博主:https://blog.csdn.net/amovement/article/details/80358962 B. Bus of Characters time limit per tes ...
- Bus of Characters(栈和队列)
In the Bus of Characters there are nn rows of seat, each having 22 seats. The width of both seats in ...
- 自定义模拟一个Spring IOC容器
一.模拟一个IOC容器: 介绍:现在,我们准备使用一个java project来模拟一个spring的IOC容器创建对象的方法,也就是不使用spring的jar自动帮助我们创建对象,而是通过自己手动书 ...
- 使用LinkedList模拟一个堆栈或者队列数据结构
使用LinkedList模拟一个堆栈或者队列数据结构. 堆栈:先进后出 如同一个杯子. 队列:先进先出 如同一个水管. import java.util.LinkedList; public cl ...
- scala模拟一个timer
直接上代码: package com.test.scalaw.test.demo import java.util.Date /** * 模拟一个定时timer */ object Timer { d ...
- C# 模拟一个处理消息队列的线程类 Message Queue
// 模拟一个处理消息队列的类 class MessageHandler { // 消息队列 private Queue<string> messageQue = new Queue< ...
- java集合 collection-list-LinkedList 模拟一个堆栈或者队列数据结构。
/* 使用LinkedList模拟一个堆栈或者队列数据结构. 堆栈:先进后出 如同一个杯子. 队列:先进先出 First in First out FIFO 如同一个水管. */ import jav ...
- jquery用div模拟一个下拉列表框
原文 jquery用div模拟一个下拉列表框 今天分享一个用我自己用jquery写的,用div模拟下拉列表select,这个效果网上有很多,但是写一个有自己思路的代码效果,更有成就感,先看截图: 自我 ...
随机推荐
- Response.Redirect(),Server.Transfer(),Server.Execute()的区别与网站优化
转 http://blog.csdn.net/dannywj1371/article/details/10213631 1.Response.Redirect():Response.Redirect方 ...
- Mac 安装cmake小问题
今天用 brew install cmake. ==> Downloading https://homebrew.bintray.com/bottles/cmake-3.9.6.sierra.b ...
- MVC、控件、一般处理程序中的session and cookie
Mvc中: session: if (!string .IsNullOrEmpty(find)) //设置 Session["oip"] = "无锡"; Vie ...
- .NET MVC权限设计思考之切入点
在WebForm下我们一般会设计个PageBase继承Page,在OnInit方法中实现对基本权限的验证业务,然后所有的页面在继承PageBase直接继承这项基本权验证业务.而在.NET MVC下我们 ...
- PopupWindow实现点击外部不消失
View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.alert_ip, null); final Po ...
- APUE学习笔记7——进程间通信
1 管道 管道一般是一种半双工的进程间通信方式,只能够在具有公共祖先的进程之间使用,比如一个管道由一个进程创建,然后该进程调用fork,之后父.子进程就可以使用该管道. 管道是调用pipe函数创建的. ...
- 深入浅出JDK动态代理(一)
1.何为代理 代理,即代替主角完成一些额外的事情.例如,明星都有经纪人,明星参演电影之前,经纪人作为明星的代理人和出资方洽谈片酬.排期等,而真正参与拍戏的还是明星本人,明星拍完戏后,由经纪人代理明星去 ...
- 阿里logo库
http://www.iconfont.cn/home/index?spm=a313x.7781069.1998910419.2
- CorelDRAW X8制作金属质感3D立体按钮
本教程教您使用CorelDRAW X8制作金属质感3D立体按钮.绘图中主要应用渐变填充技巧为立体按钮表现物体质感和丰富的色彩变化,最后实现的效果也是不错的,是很实用的案例,教程难度一般,完成图如下: ...
- Hihocoder1061-Beautiful String
时间限制:10000ms单点时限:1000ms内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 or ...