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使用排列组 ...
随机推荐
- [原创]Fashion汽车定位器拆解
随着共享单车的爆发增长,定位方案被彻底激活.当下主流的共享单车都采用了MTK2503的方案(后续再详细分解),本文针对某商城热卖的汽车定位器进行拆解分析. 第一部分,定位器外观. 第二部分,拆解开壳, ...
- 公开的免费WebService接口分享
天气预报Web服务,数据来源于中国气象局 Endpoint Disco WSDL IP地址来源搜索 WEB 服务(是目前最完整的IP地址数据) Endpoint Disco WSDL 随机英文 ...
- CocoaPods 添加WebP失败解决办法
pod 'sdwebimage/webp' 下载libwebp 超时 [!] Error installing libwebp [!] /usr/bin/git clone https://chrom ...
- CF 1131C Birthday
C. Birthday time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 2.node.js (二)服务器登录注册 与 包的发布
get: 不安全 小 2k 数据会在地址栏上显示 从服务器获取 快 post: 相对安全 https 大 1G 不会 向服务器发送 慢 get:直接解析url地址 借助 url模块 var urlOb ...
- orace函数
处理字符的函数 lower(char);//把字符串转换成小写格式 upper(char);//把字符转换成大写 length(char);//返回字符串的长度 substr(char,m,n);// ...
- 怎么在Centos7 下让我的mariadb开机启动?(已解决)
以前我经常使用syscemctl工具在开机后执行 systemctl start mariadb (哈哈,打得可6,只是有点儿麻烦), 如果能开机自启动mariadb就好了. 所以,我想百度下看什么命 ...
- DWZ富客户端框架+DWZ简介及其使用+DWZ讨论组
DWZ富客户端框架+DWZ简介及其使用+DWZ讨论组 地址: DWZ富客户端框架:http://jui.org/#_blank DWZ简介及其使用:http://blog.sina.com.cn/s/ ...
- stm32f7699遇到的犯二问题
没有看到stlink的驱动,难道板子坏了?? 结果:USB线的问题,换了一根用过的线,就行了:
- 什么是Rollback Segment(已truncate和delete 命令为例)?
Rollback Segments是在你数据库中的一些存储空间,它用来临时的保存当数据库数据发生改变时的先前值,Rollback Segment主要有两个目的: 1. 如果因为某种原因或者其他用用户想 ...