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使用排列组 ...
随机推荐
- macbook air 2012 mid 安装 windows10 双系统遇到错误 no bootable device insert boot disk and press any key
macbook型号:air 2012 mid 当前操作系统:mojave 安装工具:boot camp assistant 要安装的双系统:windows 10家庭版 安装教程:百度搜一堆 安装过程中 ...
- ocelot配置
动态配置 { "ReRoutes": [], "Aggregates": [], "GlobalConfiguration": { &quo ...
- windows环境下redis启动加到服务中
前置条件: 1.命令运行在redis-server.exe目录下 2.cmd命令 安装命令: redis-server.exe --service-install redis.windows.co ...
- CentOS 6.8 防火墙配置
系统: CentOS release 6.8 (Final) iptables v1.4.7 执行命令: #清除所有规则 iptables -F #开放redis端口 iptables -A INPU ...
- Linux set、env、declare、export显示shell变量的区别
目录 Linux中 set.env.declare.export显示shell变量的区别 1. shell局部变量 2. 用户的环境变量 显示shell变量 declare 命令 export 命令 ...
- 【数据库问题】sql server 获取MD5值结果不一致的问题 substring(sys.fn_sqlvarbasetostr(HashBytes('MD5','111111')),11,32)
获取 111111 的MD5值 SELECT substring(sys.fn_sqlvarbasetostr(HashBytes(,) 执行结果:965eb72c92a549dd5a330112 但 ...
- Python Pandas 箱线图
各国家用户消费分布 import numpy as np import pandas as pd import matplotlib.pyplot as plt data = { 'China': [ ...
- 洛谷P3384 【模板】树链剖分
题目描述 如题,已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作1: 格式: 1 x y z 表示将树从x到y结点最短路径上所有节点的值都加上z 操作2: 格式 ...
- mpdf中文开发使用文档附demo实例
官网URL:http://www.mpdf1.com/mpdf/index.php github:https://github.com/mpdf/mpdf 官方开发手册,英文的:http://www. ...
- java面试基础题------》Java 中List、Set、Map异同点
借鉴地址:http://blog.csdn.net/speedme/article/details/22398395 几句喜欢的话,拷贝下来: 世间上本来没有集合,(只有数组参考C语言)但有人想要,所 ...