Codeforces 890B - Vlad and Cafes Set
B. Vlad and Cafes
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.
Input
In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad.
In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.
Output
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
Examples
input
5
1 3 2 1 2
output
3
input
6
2 1 2 2 4 1
output
2
Note
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.
思路:
利用Set添加元素,从后到前删除元素,size==1,停止,输出set中的begin元素
代码:
#include <bits/stdc++.h>
using namespace std;
int ans[];
set<int> s;
int main() {
ios::sync_with_stdio(false);
int n;
scanf("%d",&n);
for(int i=;i<=n;++i) {
scanf("%d",&ans[i]);
s.insert(ans[i]);
}
for(int i=n;i>=;--i) {
if(s.size()==)
break;
if(s.find(ans[i])!=s.end()) {
s.erase(ans[i]);
}
}
printf("%d\n",*s.begin());
return ;
}
Codeforces 890B - Vlad and Cafes Set的更多相关文章
- Codeforces Round #445 B. Vlad and Cafes【时间轴】
B. Vlad and Cafes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...
- 题解【Codeforces886B】Vlad and Cafes
本题是模拟题. 我们可以用b数组记录每个数字在a数组中出现的最后位置,然后从0到2·10^5依次寻找最后一次出现最早的数(注意是0!),最后统计输出即可. AC代码: #include <bit ...
- Codeforces Round #445
ACM ICPC 每个队伍必须是3个人 #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~
C. Pie or die Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/ ...
- Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟
B. Pyramid of Glasses 题目连接: http://www.codeforces.com/contest/676/problem/B Description Mary has jus ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...
随机推荐
- 【机器学习】支持向量机(SVM)
感谢中国人民大学胡鹤老师,课程深入浅出,非常好 关于SVM 可以做线性分类.非线性分类.线性回归等,相比逻辑回归.线性回归.决策树等模型(非神经网络)功效最好 传统线性分类:选出两堆数据的质心,并做中 ...
- .7-Vue源码之AST(3)
上一节到了parseHTML函数,该函数接受一个字符串与一个对象,字符串即对应的DOM,对象包含几个字符串匹配集及3个长函数. 简略梳理部分函数代码如下: // Line-7672 function ...
- C#读写Shapefile
Shapefile文件是ArcGIS存储矢量要素的标准格式,要读写Shapefile最简单的方法当然是基于ArcObject(或者ArcEngine)开发,不过网上也有一些开源的解译Shapefile ...
- TreeView简单的动态加载数据
简单的小记录,省得去看控件属性详情了,基本常用的属于就几个 先是判断根节点是否存在控件中,如果不存在则创建,之前要添加了节点同样的方法 把根节点传到子节点的方法中,再判断是否在根节点里存在子节点,如果 ...
- HDU1754 I hate it(线段树 单点修改)
好久没打线段树,来一道练练手,但说句实话,I really hate it!!!! 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管 ...
- CIFAR-10 dataset 的下载与使用
基本信息 CIFAR-10 是一个包含60000张图片的数据集.其中每张照片为32*32的彩色照片,每个像素点包括RGB三个数值,数值范围 0 ~ 255. 所有照片分属10个不同的类别,分别是 'a ...
- Luogu P2183 巧克力
题目描述 佳佳邀请了M个同学到家里玩.为了招待客人,她需要将巧克力分给她的好朋友们.她有N(1<=N<=5000)块巧克力,但是大小各不一样,第i块巧克力大小为为1*Xi(1<=i& ...
- ORM框架SQLAlchemy与权限管理系统的数据库设计
SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用对象关系映射进行数据库操作,即:将对象转换成SQL,然后使用数据API执行SQL并获取执行结果. 执行流 ...
- 设计模式的征途—9.组合(Composite)模式
树形结构在软件中随处可见,比如操作系统中的目录结构,公司组织结构等等,如何运用面向对象的方式来处理这种树形结构是组合模式需要解决的问题.组合模式通过一种巧妙的设计方案来使得用户可以一致性地处理整个树形 ...
- Python学习二:词典基础详解
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/7862377.html 邮箱:moyi@moyib ...