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 题解的更多相关文章

  1. 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 ...

  2. Chat Order (map映射)

     Chat Order Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit ...

  3. codeforces 637B B. Chat Order(map,水题)

    题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. 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 ...

  5. LeetCode Intersection of Two Arrays

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...

  6. LeetCode Reconstruct Itinerary

    原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...

  7. Group Shifted Strings

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  8. PHP_D4_“简易聊天室 ”的具体技术实现

    上面已经介绍了系统的关键技术,下面对具体实现进行详解: 1.开发时,经常需要利用一个配置文件来存储系统的参数,例如:数据库连接信息等.这样可以提高系统的可移植性,当系统的配置发生变化时,例如:更改服务 ...

  9. 第15届浙江省赛 D Sequence Swapping(dp)

    Sequence Swapping Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao has just found a strange s ...

随机推荐

  1. 【JavaSE】格式化输出

    Java格式化输出 2019-07-06  11:35:55  by冲冲 1. 输出字符串 %s 1 /*** 输出字符串 ***/ 2 // %s表示输出字符串,也就是将后面的字符串替换模式中的%s ...

  2. SQL 跨实例操作

    SQL 跨实例操作 我使用的是 OpenDataSource 函数,假设你要在其他机器上访问 192.168.0.1 上的数据库: SELECT A.[Name], B.[SkillName], B. ...

  3. CF1555F Good Graph

    有以下引理: 不存在两个合法环,他们存在公共边. 证明:公共边边权为 \(z\),第一个环除去公共边为 \(x\),第二个环除去公共边为 \(y\). 则有 \(x \oplus z = 1\) \( ...

  4. 用 AppImage文件创建快捷图标和软连接

    背景 AppImage是一种在Linux系统中用于分发便携式软件而不需要超级用户权限来安装它们的格式.[1] 它还试图允许Linux的上游开发者来分发他们的程序而不用考虑不同Linux发行版间的区别. ...

  5. Python如何支持读入gz压缩或未压缩文件?

    目录 需求 示例代码 笨办法 Pythonic方法 需求 要写一个接口,同时支持压缩和未压缩文件读入 示例代码 笨办法 import os import gzip filename = sys.arg ...

  6. 从Redis分布式缓存实战入手到底层原理分析、面面俱到覆盖大厂面试考点

    概述 官方说明 Redis官网 https://redis.io/ 最新版本6.2.6 Redis中文官网 http://www.redis.cn/ 不过中文官网的同步更新维护相对要滞后不少时间,但对 ...

  7. 14. GLIBCXX_3.4.9' not found - 解决办法

    在Linux中安装交叉编译器arm-linux-gcc 4.4.3,然后编译mini2440内核出错: /usr/lib/libstdc++.so.6: version GLIBCXX_3.4.9' ...

  8. Go语言核心36讲(Go语言实战与应用二十三)--学习笔记

    45 | 使用os包中的API (下) 我们在上一篇文章中.从"os.File类型都实现了哪些io包中的接口"这一问题出发,介绍了一系列的相关内容.今天我们继续围绕这一知识点进行扩 ...

  9. 如何启动、关闭和设置ubuntu防火墙 (转载)

    引自:http://www.cnblogs.com/jiangyao/archive/2010/05/19/1738909.html 由于LInux原始的防火墙工具iptables过于繁琐,所以ubu ...

  10. Output of C++ Program | Set 1

    Predict the output of below C++ programs. Question 1 1 // Assume that integers take 4 bytes. 2 #incl ...