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 < ...
随机推荐
- Windows下如何更新 CodeBlocks 中的 MinGW 使其支持新版本 C++
转自:http://blog.csdn.net/wtfmonking/article/details/17487705 虽然 CodeBlocks16.01 已经是最新版了,但其中的 MinGW 仍然 ...
- 2198: 小P当志愿者送餐
题目描述 在ICPC程序设计大赛期间,小P作为志愿者的任务是给各个学校送盒饭,小P一次最多可以携带M份盒饭.总共有N个学校来参加比赛,这N个学校的休息点在一条笔直的马路边一字排开,路的一头是小P取盒饭 ...
- Unix / Linux 线程的实质
线程与进程的比较 概述: 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位. 线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小 ...
- POJ - 3468 线段树区间修改,区间求和
由于是区间求和,因此我们在更新某个节点的时候,需要往上更新节点信息,也就有了tree[root].val=tree[L(root)].val+tree[R(root)].val; 但是我们为了把懒标记 ...
- Python学习第二篇
list_num=list(range(1,1000001)) print(min(list_num)) print(max(list_num)) print(sum(list_num)) print ...
- PHP实用代码片段(一)
1. 发送 SMS 在开发 Web 或者移动应用的时候,经常会遇到需要发送 SMS 给用户,或者因为登录原因,或者是为了发送信息.下面的 PHP 代码就实现了发送 SMS 的功能. 为了使用任何的语言 ...
- XML 与 JSON大PK
导读 XML 和 JSON 是现今互联网中最常用的两种数据交换格式.XML 格式由 W3C 于 1996 年提出.JSON 格式由 Douglas Crockford 于 2002 年提出.虽然这两种 ...
- oc之封装「可输入值」的UIStepper
2017.07.17 18:10* 字数 66 阅读 644评论 0喜欢 5 oc之封装「可输入值」的UIStepper 最终效果 要求: Platform: iOS7.0+ Language: Ob ...
- nginx 编译安装以及简单配置
前言 Nginx的大名如雷贯耳,资料太多了,网上一搜一大把,所以这里就不阐述nginx的工作原理了,只是简单的编译安装nginx,然后呢,简单配置一下下. 下载Nginx.安装 下载地址:http:/ ...
- 遍历List过程中删除操作报java.util.ConcurrentModificationException错误
1:遍历List 同时 remove 元素,出现java.util.ConcurrentModificationException错误 @Test public void test3(){ List& ...