CF637B Chat Order 题解
Content
有 \(n\) 个字符串,每次出现这个单词就把这个单词放到队列的队首(若已经出现就把原队列里面的那个单词提到队首),求最后的队列由队首到队尾的元素依次是多少。
数据范围:\(1\leqslant n\leqslant 2\times 10^5\)。
Solution
直接用结构体存储一下每个字符串最后出现的位置(可以用 \(\texttt{map}\) 直接映射),然后我们按出现的位置从大到小排序即可。
Code
#include <cstdio>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
struct node {
string name;
int last;
bool operator < (const node& cjy) const {return last > cjy.last;}
}a[200007];
map<string, int> vis;
int n, cnt;
int main() {
//This program is written in Ubuntu 16.04 by Eason_AC
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
string s;
cin >> s;
if(!vis[s]) {
a[++cnt].name = s;
vis[s] = cnt;
}
a[vis[s]].last = i;
}
sort(a + 1, a + cnt + 1);
for(int i = 1; i <= cnt; ++i)
cout << a[i].name << endl;
return 0;
}
CF637B Chat Order 题解的更多相关文章
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题
B. Chat Order 题目连接: http://www.codeforces.com/contest/637/problem/B Description Polycarp is a big lo ...
- Chat Order (map映射)
Chat Order Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit ...
- codeforces 637B B. Chat Order(map,水题)
题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- VK Cup 2016 - Qualification Round 1——B. Chat Order(试手stack+map)
B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...
- LeetCode Intersection of Two Arrays
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...
- LeetCode Reconstruct Itinerary
原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...
- Group Shifted Strings
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- PHP_D4_“简易聊天室 ”的具体技术实现
上面已经介绍了系统的关键技术,下面对具体实现进行详解: 1.开发时,经常需要利用一个配置文件来存储系统的参数,例如:数据库连接信息等.这样可以提高系统的可移植性,当系统的配置发生变化时,例如:更改服务 ...
- 第15届浙江省赛 D Sequence Swapping(dp)
Sequence Swapping Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a strange s ...
随机推荐
- 【PS】证件照转换背景色
证件照转换背景色 2019-07-14 12:18:49 by冲冲 1. 需求 自由切换证件照的背景颜色(白底.蓝底.红底...) 2. 步骤 ① 双击 图层锁 解锁,弹出的"新建图层0 ...
- spring-整合es
spring-整合es 导入pom <?xml version="1.0" encoding="UTF-8"?> <project xmln ...
- es使用postmain进行数据的增删改查
es的基本安装 安装遇到的问题 java本地环境和es环境冲突 https://www.cnblogs.com/q1359720840/p/14077049.html ,看要使用jdk1 ...
- 百胜中国使用Rainbond实现云原生落地的实践
百胜中国使用Rainbond实现云原生落地的实践 关于百胜中国 自从1987年第一家餐厅开业以来,截至2021年第二季度,百胜中国在中国大陆的足迹遍布所有省市自治区,在1500多座城镇经营着11023 ...
- .NET E F(Entity Framework)框架 DataBase First 和 Code First 简单用法。
EF是微软.NET平台官方的ORM(objet-relation mapping),就是一种对象-关系 映射,是将关系数据库种的业务数据用对象的形式表现出来,并通过面向对象的方式讲这些对象组织起来,实 ...
- R语言与医学统计图形-【31】动态交互绘图
1.plotly包 动态散点图 library(plotly) # 交互散点图 plot_ly(data=iris, x=~Sepal.Length, y=~Petal.Length, marker= ...
- 30-Container With Most Water-Leetcode
Given n non-negative integers a1, a2, -, an, where each represents a point at coordinate (i, ai). n ...
- centos 安装reids
1.安装tcl支持 yum install tcl 2.安装redis我们以最新的2.8.9为例 $ wget http://download.redis.io/releases/redis-2.8. ...
- 数据集成工具—Sqoop
数据集成/采集/同步工具 @ 目录 数据集成/采集/同步工具 Sqoop简介 Sqoop安装 1.上传并解压 2.修改文件夹名字 3.修改配置文件 4.修改环境变量 5.添加MySQL连接驱动 6.测 ...
- gen already exists but is not a source folder. Convert to a source folder or rename it 的解决办法
1. Right click on the project and go to "Properties" //鼠标右键点击项目,然后选中Properties 2. Select ...