bzoj 2761: [JLOI2011]不重复数字 (map||Treap)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2761
思路: map标记
实现代码:
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
int t,n,x;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = ;i <= n;i ++){
scanf("%d",&x);
mp[x]++;
if(mp[x]==) printf("%d ",x);
}
printf("\n");
mp.clear();
}
}
这道题也可以用平衡树写,虽然也很水/////
Treap写法:
实现代码:
#include<bits/stdc++.h>
using namespace std;
const int M = 1e5 +;
struct node{
int l,r,siz,cnt,wt,val;
}t[M];
int cnt,flag; void lt(int &k){
int tmp = t[k].r;
t[k].r = t[tmp].l;
t[tmp].l = k;
t[tmp].siz = t[k].siz;
t[k].siz = t[t[k].l].siz + t[t[k].r].siz + t[k].cnt;
k = tmp;
} void rt(int &k){
int tmp = t[k].l;
t[k].l = t[tmp].r;
t[tmp].r = k;
t[tmp].siz = t[k].siz;
t[k].siz = t[t[k].l].siz + t[t[k].r].siz + t[k].cnt;
k = tmp;
} void Insert(int &k,int num){
if(!k){
k = ++cnt;
t[k].wt = rand();
t[k].val = num;
t[k].cnt = t[k].siz = ;
return ;
}
++t[k].siz;
if(num == t[k].val){
++t[k].cnt;
flag = ;
return ;
}
if(num < t[k].val){
Insert(t[k].l,num);
if(t[t[k].l].wt < t[k].wt) rt(k);
}
else{
Insert(t[k].r,num);
if(t[t[k].r].wt < t[k].wt)
lt(k);
}
} int main()
{
int T,n,x,root;
scanf("%d",&T);
while(T--){
memset(t,,sizeof(t));
root = cnt = ;
scanf("%d",&n);
for(int i = ;i <= n;i ++){
cin>>x;
flag = ;
Insert(root,x);
if(!flag) printf("%d ",x);
}
printf("\n");
}
return ;
}
bzoj 2761: [JLOI2011]不重复数字 (map||Treap)的更多相关文章
- bzoj 2761 [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3210 Solved: 1186[Submit][Sta ...
- BZOJ 2761: [JLOI2011]不重复数字 水题
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2100 Solved: 809 题目连接 http:// ...
- BZOJ 2761: [JLOI2011]不重复数字 set
Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...
- BZOJ 2761: [JLOI2011]不重复数字 hash哈希
题目就不贴了 点我看题 题意:这题题意很简明,就是给一个序列,把序列里相同的删掉,然后输出,按原数列顺序. 思路:这题之前QZZ和ZN大神犇叫我去做,辣时还不会hash,就留着了.最近某夏令营学会了h ...
- bzoj 2761: [JLOI2011]不重复数字【hash】
map会T,双hash会冲突--于是非酋写了个三hash #include<iostream> #include<cstdio> #include<cstring> ...
- bzoj 2761: [JLOI2011]不重复数字
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...
- 2761: [JLOI2011]不重复数字(平衡树)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2133 Solved: 825[Submit][Stat ...
- 2761: [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1770 Solved: 675[Submit][Stat ...
- 【BZOJ】2761: [JLOI2011]不重复数字(set+巨水题+超坑题)
http://www.lydsy.com/JudgeOnline/problem.php?id=2761 太水了,不说了. 但是这格式错误我已经没话说了....行末不能有空格 #include < ...
随机推荐
- React-redux框架之connect()与Provider组件 用法讲解
react-redux 在react-redux 框架中,给我提供了两个常用的API来配合Redux框架的使用,其实在我们的实际项目开发中,我们完全可以不用react-redux框架,但是如果使用此框 ...
- c++入门之结构体初步
结构体实际上是一种数据结构的雏形,对结构体的灵活使用很多时候可以带来很多便利.下面给出一个关于结构体的程序: #include "iostream" # include " ...
- Python学习第二篇
list_num=list(range(1,1000001)) print(min(list_num)) print(max(list_num)) print(sum(list_num)) print ...
- mysql常用命令行操作(二):表和库的操作、引擎、聚合函数
一.查看.创建.删除数据库 create database library default character set utf8 collate utf8_general_ci; # 创建数据库并设置 ...
- 【转】实现Nginx代理WSS协议
https://blog.csdn.net/chopin407/article/details/52937645 后来看到了官网的教程(http://nginx.org/en/docs/http/we ...
- [转帖]windows7/windows NT介绍
windows7/windows NT介绍 原文应该是IT168发布的 但是一直没找到 感觉看了之后 明白了很多 技术都是互相融合的 没有严格意义上的对立直说. Windows 7/Windows ...
- 剑指offer(6)
题目: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...
- Linux基础操作二
编程语言的作用及与操作系统和硬件的关系 编程语言的作用:用来定义计算机程序的形式,程序员用它来编写程序,进而控制其向计算机发出指令,使计算机完成人类布置的任务. 编程语言的作用及与操作系统和硬件的关系 ...
- jenkins 邮箱设置
一.先设置管理员邮箱地址 二.设置邮箱
- php new self()
php里new self() 一般在类内部使用,作用是对自身类实例化 <?php class test{ public function __construct(){ echo ' ...