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

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

  2. 【Codeforces Round #445 (Div. 2) B】Vlad and Cafes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 傻逼模拟 [代码] #include <bits/stdc++.h> using namespace std; cons ...

  3. 题解【Codeforces886B】Vlad and Cafes

    本题是模拟题. 我们可以用b数组记录每个数字在a数组中出现的最后位置,然后从0到2·10^5依次寻找最后一次出现最早的数(注意是0!),最后统计输出即可. AC代码: #include <bit ...

  4. Codeforces Round #445

    ACM ICPC 每个队伍必须是3个人 #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu ...

  5. Codeforces Round #354 (Div. 2)-B

    B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...

  6. 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/ ...

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

  8. Codeforces Round #562 (Div. 2) A.Circle Metro

    链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...

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

随机推荐

  1. MySql数据库的基本原理及指令

    1.什么是数据库 数据库就是存储数据的仓库,其本质是一个文件系统,数据按照特定的格式将数据存储起来,用户可以通过SQL对数据库中的数据进行增加,修改,删除及查询操作. 2.简介 MySQL是一个开放源 ...

  2. python参考手册一书笔记之第一篇上

    在python2和python3的版本差异很大输出hello world的方法在2里支持在3里就不支持了. print 'hello world' #在2中支持 print ('hello world ...

  3. Spring + Fastweixin 微信开发

    这篇文章转自<http://www.qtdebug.com/spring-weixin/> 微信有两种模式,编辑模式和开发者模式,有些功能是互斥的,不可以同时使用,微信开发需要在开发者模式 ...

  4. 使用fabric解决百度BMR的spark集群各节点的部署问题

    前言 和小伙伴的一起参加的人工智能比赛进入了决赛之后的一段时间里面,一直在构思将数据预处理过程和深度学习这个阶段合并起来.然而在合并这两部分代码的时候,遇到了一些问题,为此还特意写了脚本文件进行处理. ...

  5. 原生js+css实现重力模拟弹跳系统的登录页面

    今天小颖把之前保存的js特效视频看了一遍,跟着视频敲了敲嘻嘻,用原生js实现一个炫酷的登录页面.怎么个炫酷法呢,看看下面的图片大家就知道啦. 效果图: 不过在看代码之前呢,大家先和小颖看看css中的o ...

  6. 【JDK1.8】JDK1.8集合源码阅读——LinkedHashMap

    一.前言 在上一篇随笔中,我们分析了HashMap的源码,里面涉及到了3个钩子函数,用来预设给子类--LinkedHashMap的调用,所以趁热打铁,今天我们来一起看一下它的源码吧. 二.Linked ...

  7. 隐藏input的光标

    https://segmentfault.com/q/1010000000684888 https://wap.didialift.com/beatles/campaign/driver/activi ...

  8. chrome Web开放 字体格式不能显示问题

    /** * Chrome 32/33 webfont issue fix. * Requires jQuery. * More info: http://blog.cloudfour.com/chro ...

  9. 企业级memcached部署(session共享)

    服务端部署 第一个里程碑:安装依赖关系 Memcache用到了libevent这个库用于Socket的处理. [root@nfs01 ~]# yum install libevent libevent ...

  10. HTML 3秒一换轮播(鼠标选中旋转停止定时) 动画案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...