CF978A Remove Duplicates【数组操作/STL】
【链接】:CF978A
【分析】:逆向思考+标记数组去重
【代码】:
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
#define ms(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(a); i<(b); i++)
//#define run(i,a,b) for(int i=(a); i<=(b); i++)
const int N = 1e5+5;
#define ll long long
int n;
int v[N];
int b[N];
int a[N];
set<int> st;
vector<int> vt;
int main()
{
cin>>n;
rep(i,0,n)
{
cin>>a[i];
st.insert(a[i]);
}
cout<<st.size()<<endl;
for(int i=n-1;i>=0;i--)
{
if(v[a[i]]==0)
{
vt.push_back(a[i]);
}
v[a[i]]=1;
}
for(int i=st.size()-1;i>=0;i--)
{
printf("%d ",vt[i]);
}
}
CF978A Remove Duplicates【数组操作/STL】的更多相关文章
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法
Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II ☆☆☆(从有序数组中删除重复项之二)
https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/discuss/27976/3-6-easy-lines-C% ...
- [LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)
[LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the d ...
- 【数组】Remove Duplicates from Sorted Array II
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- LeetCode OJ:Remove Duplicates from Sorted Array II(移除数组中的重复元素II)
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- [LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
随机推荐
- [转]赵桐正thinkphp教程笔记
原文:赵桐正thinkphp教程笔记 ,有修改 常用配置 常用配置config.php: <?php return array( //'配置项'=>'配置值' 'URL_PATHINFO_ ...
- Visual Studio使用技巧笔记(引用程序集自动复制dll到引用项目目录)
copy /y $(TargetPath) $(SolutionDir)\[您项目引用dll文件的目录]\$(TargetFileName) 例如:copy /y $(TargetPath) $(So ...
- 遍历两个自定义列表来实现字典(key:value)
#自定义key ${keys} create list key1 key2 key3 #自定义value ${values} create list v ...
- linux_shell基础-变量、数组、运算符
#!/bin/bash# echo 'hello world'# name='http://www.baidu.com'# for file in $(ls ./); do# echo "t ...
- css3 skew坐标轴笔记
transform是css3中对于性能来说是比较安全的 在二维空间里面,skew有两个属性值:skewX,skewY,图形的变化也就是针对这两个值来操作: transform: skewX(45deg ...
- 使用 JsonPath 完成接口自动化测试中参数关联和数据验证(Python语言)
背景: 接口自动化测试实现简单.成本较低.收益较高,越来越受到企业重视 restful风格的api设计大行其道 json成为主流的轻量级数据交换格式 痛点: 接口关联 也称为关联参数.在应用业务接口中 ...
- MySQL事物相关学习
总结下最近对MySQL数据库的认识 Q:在手动开启事物后,commit失败是否需要显示的rollback? A:在网上查了不少资料,没有查到明确的答案.问了身边的朋友,朋友也不太了解,不过均表示显示的 ...
- CodeForces Round #515 Div.3 A. Vova and Train
http://codeforces.com/contest/1066/problem/A Vova plans to go to the conference by train. Initially, ...
- token的作用
token的作用 基于 Token 的身份验证方法 使用基于 Token 的身份验证方法,在服务端不需要存储用户的登录记录.大概的流程是这样的: 客户端使用用户名跟密码请求登录 服务端收到请求,去验证 ...
- 安装bcc
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D4284CDD echo "deb https://repo.i ...