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 ...
随机推荐
- HTML四种定位-绝对定位
绝对定位 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset=&q ...
- adb server version (32) doesn't match this client (39); killing...解决办法
输入今天遇到,安装AndroidSDK之后,已经配置好环境变量,输入adb可运行,但是输入adb devices之后就出现adb server version (32) doesn't match t ...
- SimpleNVR安防监控RTSP/FLV/HLS直播流服务如何分权限添加用户指定通道观看
背景分析 随着SimpleNVR的用户越来越多,很多客户反馈给了我们很宝贵的简易以及用户体验.在此非常感谢大家对我们的支持.其中很多客户不想把所有的视频直播展现出来,想分权限添加新用户,指定通道让其观 ...
- Jmeter——变量嵌套函数使用(__V)案例分析
jmeter版本:5.3 __V官方函数解释: (https://jmeter.apache.org/usermanual/functions.html#__V) 图1-1 解决问题:实现字符串拼接 ...
- 探索JavaScript执行机制
前言 不论是工作还是面试,我们可能都经常会碰到需要知道代码的执行顺序的场景,所以打算花点时间彻底搞懂JavaScript的执行机制. 如果这篇文章有帮助到你,️关注+点赞️鼓励一下作者,文章公众号首发 ...
- Atcoder Regular Contest 089 D - ColoringBalls(DP)
Atcoder 题面传送门 & 洛谷题面传送门 神仙题. 在下文中,方便起见,用 R/B 表示颜色序列中球的颜色,用 r/b 表示染色序列中将连续的区间染成的颜色. 首先碰到这一类计算有多少个 ...
- Codeforces Round #681 (Div. 1) Solution
A. Extreme Subtraction 把这个数组差分一下,发现操作一的作用是把 \(d_1\) 的大小分给 \(d_i\),而操作二的作用是把 \(d_i\) 减去任意值,目标是把 \(d\) ...
- 【Plink】Error: Multiple instances of '_' in sample ID.?
目录 前言 原因 解决方法 方法一:修改样本名 方法二:修改--id-delim 方法三:加入--double_id或--const-fid参数 前言 将vcf转化为plink格式时,命令如下: pl ...
- 编程艺术第十六~第二十章:全排列/跳台阶/奇偶调序,及一致性Hash算法
目录(?)[+] 第十六~第二十章:全排列,跳台阶,奇偶排序,第一个只出现一次等问题 作者:July.2011.10.16.出处:http://blog.csdn.net/v_JULY_v. 引言 ...
- nuxt使用图片懒加载vue-lazyload
对于nuxt使用第三方插件的方式大体都是都是一致的,就是在plugins文件夹中新增插件对应的js文件进行配置与操作,然后在nuxt.config.js文件的plugins配置项中引入新建的js文件就 ...