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 < ...
随机推荐
- vue的高阶组件
探索Vue高阶组件 探索Vue高阶组件的使用 Vue高阶组件的使用方法 高阶组件应用-组件重新实例化 深入理解React 高阶组件 探索Vue高阶组件 2018-01-05 探索Vue高阶组件 Vue ...
- duxing201606的原味鸡树
链接 [http://murphyc.fun/problem/4011] 题意 描述 众所周知,duxing哥非常喜欢原味鸡.众所周知,原味鸡是长在原味鸡树上的. duxing哥因为是水产巨子,所以就 ...
- anaconda安装win10
注意事项: 1.下载安装,双选勾勾 2.安装python3.5的版本 conda create -n tensorflow python=3.5 3.激活环境activate tensorflow 4 ...
- http/https与websocket的ws/wss的关系以及通过Nginx的配置
http/https与websocket的ws/wss的关系 - 哒哒哒 - CSDN博客 https://blog.csdn.net/Garrettzxd/article/details/81674 ...
- JMeter学习non-gui模式运行
-h, --help print usage information and exit #打印帮助信息 -v, --version print the version information and ...
- jmeter 启动jmeter-server.bat远程调用报错: java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)
1.找到apache-jmeter-5.0\bin\jmeter.properties 2.修改server.rmi.ssl.disable=true (记得去除server.rmi.ssl.disa ...
- cmd远程连接oracle数据库
- Eclipse导入工程后出现中文乱码
Eclipse之所以会出现乱码问题是因为eclipse编辑器选择的编码规则是可变的.一般默认都是UTF-8或者GBK,当从外部导入的一个工程时,如果该工程的编码方式与eclipse中设置的编码方式不同 ...
- Hbase的作用
实时动态增加列 多版本的意思为多个用户地址,多个用户信息,多个用户号码
- centos6.8安装JDK
1.检测当前系统安装jdk信息 rpm -qa | grep jdk 2.如果检查到有安装信息,则用sudo yum remove XXX(XXX代表上面查到的结果) 3.下载rpm包,安 ...