题解【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 ...
随机推荐
- Java中WEAK_PASSWORD_HASH的修改策略
在采用SHA-256对数据进行加密时,我们可以直接采用下面的方式进行处理: public static String encodeBySha256(String content) { String e ...
- ansible-jinjia2模板
1. 含义 是基于python的模板引擎,包含变量和表达式两部分,这两者在模板求值的时候会被替换为值: 模板中还有标签,控制模板的逻辑 2. 基础语法 - 模板的表达式都包含在分隔符"{{ ...
- IntelliJ IDEA 如何彻底删除项目的步骤
原文参考链接:https://www.jb51.net/article/129473.htm 本文介绍了IntelliJ IDEA 如何彻底删除项目的步骤,分享给大家,顺便给自己留个笔记,具体如下: ...
- axios 跨域请求允许带cookie,则服务器Access-Control-Allow-Origin应设置为具体域名,否则请求无法获得返回数据
1.通过允许跨域访问实现了跨域请求,但为了使每个请求带上session信息,我设置了withCredentials ,即: axios.defaults.withCredentials = true ...
- koa文档笔记
请求 get ctx.request.query // 查询对象 ctx.request.querystring // 查询字符串 ctx.query // 查询对象 ctx.querystring ...
- php文件操作(最后进行文件常用函数封装)
文件信息相关API $filename="./1-file.php"; //filetype($filename):获取文件的类型,返回的是文件的类型 echo '文件类型为:', ...
- 插入jupyter notebook代码
<iframe src="https://nbviewer.jupyter.org/gist/gaowenxin95/53408e0f1ce268430efaad2cb1f0ca4f& ...
- 菜得一P!
什么时候才能改变粗心大意的坏毛病!太吃亏了...
- 使用VSCode创建简单的Razor Webapp--1.入门
1.下载vscode,安装dotnet core sdk 在cmd中使用命令dotnet --version可以查看当前安装的版本 2.打开vscode,设置语言和扩展 在最左边的工具栏,点击最下面的 ...
- ubuntu 开启对.htaccess的支持
1. 终端运行 sudo a2enmod 程序提示可供激活的模块名称,输入: rewrite 成功会提示 rewrite already load2. 修改/etc/apach ...