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,这个效果网上有很多,但是写一个有自己思路的代码效果,更有成就感,先看截图: 自我 ...
随机推荐
- QT-helloworld-QtCreater编写
前言:纯代码编写helloworld,解析代码含义. 一.新建空项目 新建->其他项目->Empty qmake Project 二.修改.pro文件 打开helloworld.pro文件 ...
- MEF example code
public interface IObjectResolver { } public class ObjectResolver:IObjectResolver { private Compositi ...
- Vue运行npm run dev 时修改端口
进入项目文件的config文件夹E:\myapp\myproject\config,找到index.js,修改里面的8080端口,改成8088(确定不被别的程序使用的都可以)
- 洛谷P3707 [SDOI2017]相关分析(线段树)
题目描述 Frank对天文学非常感兴趣,他经常用望远镜看星星,同时记录下它们的信息,比如亮度.颜色等等,进而估算出星星的距离,半径等等. Frank不仅喜欢观测,还喜欢分析观测到的数据.他经常分析两个 ...
- 页面加载通过javascript来修改控件属性
function changeFormElementStatus(tagNames) { var tagNameArr = tagNames.split("," ...
- 路飞学城Python-Day27(复习)
简单的socket通信 import socket client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect( ...
- Pyhton学习——Day27
# hasattr(obj,'name')-->obj.name# getattr(obj,'name',default = 'xxx')--->obj.name# setattr(obj ...
- C learn questions list
\主 题: C语言面试题大汇总,个人觉得还是比较全地!!! 作 者: free131 (白日?做梦!) 信 誉 值: 100 最近因为找工作,收集了很多C语言方面方面的面试题以及答案.现在新工作搞定了 ...
- bootstrap fileinput控件 + django后台上传、回显简单使用
一.控件下载:https://github.com/kartik-v/bootstrap-fileinput/ 官网:http://plugins.krajee.com/file-input 需要引入 ...
- [转载] Linux新手必看:浅谈如何学习linux
本文转自 https://www.cnblogs.com/evilqliang/p/6247496.html 本文在Creative Commons许可证下发布 一.起步 首先,应该为自己创造一个学习 ...