题解【Codeforces886B】Vlad and Cafes
本题是模拟题。
我们可以用b数组记录每个数字在a数组中出现的最后位置,然后从0到2·10^5依次寻找最后一次出现最早的数(注意是0!),最后统计输出即可。
AC代码:
#include <bits/stdc++.h>//万能头文件 using namespace std;//使用标准名字空间 inline int read()//快速读入
{
int f=,x=;
char c=getchar(); while(c<'' || c>'')
{
if(c=='-')f=-;
c=getchar();
} while(c>='' && c<='')
{
x=x*+c-'';
c=getchar();
} return f*x;
} int n,a[]/*输入数组*/,b[]/*存储最后一次出现的位置*/,m=/*出现最早的位置*/,ans/*答案*/; int main()
{
n=read();//输入 for(register int i=; i<=n; i++)
{
a[i]=read(); b[a[i]]=i;//记录a[i]出现的最晚位置
} for(register int i=; i<=; i++) //枚举最后一次出现最早的数,注意是从0开始!
{
if(b[i]> && b[i]<m)//如果这个数出现过且位置比当前最小值还小
{
m=b[i];//记录最小位置 ans=i;//记录答案
}
} printf("%d",ans);//输出答案 return ;//结束
}
题解【Codeforces886B】Vlad and Cafes的更多相关文章
- Codeforces 890B - Vlad and Cafes Set
B. Vlad and Cafestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputou ...
- 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 ...
- Codeforces Round #445
ACM ICPC 每个队伍必须是3个人 #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu ...
- CF 1131A,1131B,1131C,1131D,1131F(Round541 A,B,C,D,F)题解
A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
随机推荐
- P4883 mzf的考验[平衡树]
P4883 mzf的考验 维护一种数据结构 支持区间翻转 区间异或 区间求和- 显然 fhq treap 区间异或显然是拆位 ~~然后复杂度*20~~ 第一次先遍历一下整棵树 pushup 一下 就可 ...
- oracle备份与还原数据
一.表数据备份与还原 creat table 备份表 select * from 原表 where insert into 原表 select * from 备份表 二.利用备份 ...
- 06-SV随机化
1.受约束的随机测试法(CRT) 随着设计变得越来越大,要产生一个完整的激励集来测试设计的功能变得越来越困难.解决的办法是采用受约束的随机测试法自动产生测试集.CRT环境比定向测试的环境复杂,不仅需要 ...
- kindle怎么导入电子书
参考网址:https://jingyan.baidu.com/article/59a015e342a165f795886545.html
- A Bug's Life____并查集
English preparation: falsify 伪造:篡改:歪曲:证明...虚假 the sexual behavior of a rare species of bugs. 一种稀 ...
- java学习笔记之IO编程—目录和文件的拷贝
进行文件或目录的拷贝时,要先判断处理对象是文件还是目录,如果是文件则直接拷贝,如果是目录还需要拷贝它的子目录及其文件,这就需要递归处理了 import java.io.*; class FileUti ...
- cenos7 安装samba
1)安装samba应用# yum install samba samba-client2)启动Samba应用 systemctl start smb nmb3)Samba配置文件 /etc/samba ...
- Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)
This is an interactive problem. Remember to flush your output while communicating with the testing p ...
- C++-hihoCoder-1142-三分求极值[三分]
#include <bits/stdc++.h> using namespace std; typedef double db; ; db a,b,c,x,y; db dis2(db X) ...
- 如何在Windows上开启Ping或者禁止PING
方法1:命令行模式 进入服务器后 点击 开始——运行 输入命令: netsh firewall set icmpsetting 8 这样就可以在外部ping到服务器了 非常简单实用! 同样道理,如果想 ...