codeforces 982B Bus of Characters
题意:
有n排座位,每排有两个座位,每排座位的宽度都不一样。
有2 * n个人要上车,如果是内向的人,那么它会选择一排两个都是空位并且宽度最小的一排去坐;
如果是外向的人,会选择一排座位已经有人坐的,并且宽度最大的一排。
输入数据保证外向的人一定可以找到合适的位置。
问每一个人坐的排数是多少。
思路:
用map存每个长度代表的座位,两个set存没有被占in的和已经被占ex的。
如果是内向的人,每次从没有被占的选择最小的,插入已经被占的,然后从没有被占中擦除;
如果是外向的人,直接从被占的选择一个最大的,再擦除。
感觉就是考察STL的运用。
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
const int N = 4e5 + ;
set<int> ex,in;
map<int,int> mmp;
char s[N];
int main()
{
int n;
scanf("%d",&n);
for (int i = ;i <= n;i++)
{
int x;
scanf("%d",&x);
in.insert(x);
mmp[x] = i;
}
scanf("%s",s);
for (int i = ;i < * n;i++)
{
if (s[i] == '')
{
auto it = in.begin();
printf("%d ",mmp[*it]);
ex.insert(*it);
in.erase(*it);
}
else
{
auto it = ex.rbegin();
printf("%d ",mmp[*it]);
ex.erase(*it);
}
}
return ;
}
codeforces 982B Bus of Characters的更多相关文章
- 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 ...
- Codeforces 982 B. Bus of Characters(模拟一个栈)
解题思路: 排序之后模拟一个栈(也可以用真的栈),时间复杂度o(n). 代码: #include <bits/stdc++.h> using namespace std; typedef ...
- 【模拟】Codeforces 711A Bus to Udayland
题目链接: http://codeforces.com/problemset/problem/711/A 题目大意: N个字符串,每个字符串5位,找到第一个出现两个OO的并改成++输出YES和改后字符 ...
- [Codeforces 864C]Bus
Description A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After ...
- Codeforces G. Bus Number(dfs排列)
题目描述: Bus Number time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CodeForces 711A Bus to Udayland (水题)
题意:给定一个n*4的矩阵,然后O表示空座位,X表示已经有人了,问你是不能找到一对相邻的座位,都是空的,并且前两个是一对,后两个是一对. 析:直接暴力找就行. 代码如下: #pragma commen ...
- CodeForces 711A Bus to Udayland
简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...
- Codeforces 991E. Bus Number (DFS+排列组合)
解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...
随机推荐
- 框架源码系列三:手写Spring AOP(AOP分析、AOP概念学习、切面实现、织入实现)
一.AOP分析 问题1:AOP是什么? Aspect Oriented Programming 面向切面编程,在不改变类的代码的情况下,对类方法进行功能增强. 问题2:我们需要做什么? 在我们的框架中 ...
- (原)关于MEPG-2中的TS流数据格式学习
关于MEPG-2中的TS流数据格式学习 Author:lihaiping1603 原创:http://www.cnblogs.com/lihaiping/p/8572997.html 本文主要记录了, ...
- Web重温系列(二):SQLite+EF6实现本地化存储
本来我们的产品有着复杂的层次结构,作为客户端的C# WinForm是不操作数据库的.但是最近有个需求,需要将数据本地保存.可选的方案很多,比如文本文件或者XML序列化和反序列化,或者如access.d ...
- eclipse如何安裝JPA 和Data Source Explorer
安裝Data Source Explorer https://blog.csdn.net/XIAOZHI0999/article/details/61199801?utm_source=blogxgw ...
- postgresql某进程占用cpu资源过高,降不下来
由于是开发阶段,所以并没有配置postgres的参数,都是使用安装时的默认配置,以前运行也不见得有什么不正常,可是前几天我的cpu资源占用突然升高.查看进程,发现有一个postgres的进程占用CPU ...
- ToolBar样式颜色,图标设置
extends:http://blog.csdn.net/w1054993544/article/details/48339565 <resources> <style name=& ...
- HTML页面本地正常,部署到服务器稍微异常解决方案
<meta http-equiv="X-UA-Compatible" content="IE=edge" > 在IE浏览器正常显示
- js 表达式与语句
引子:表达式和语句很基础,但是有时会犯错,比如: function(){}//报错 (function(){})//不报错 function f(x){ return x + 1 }()//报错 fu ...
- java爬取网站信息和url实例
https://blog.csdn.net/weixin_38409425/article/details/78616688(出自此為博主) 具體代碼如下: import java.io.Buffer ...
- 方差+标准差+四分位数+z-score公式
一.方差公式 $S^2 = \frac{1}{N}\sum_{i=1}^{N}(X_i - \mu)^2 = \frac{1}{N}[(X_1-\mu)^2 + (X_2-\mu)^2 + ... + ...