神题...

其实这题巨水,用各种诡异的方法都能A,包括STL等等

我之所以写题解,是因为我发现了一个bug:bz和luogu时限有问题!

这题我用了两种做法:

①:直接使用STL-map(不能直接用数组,值太大了)记录一个数是否出现过即可,时间复杂度O(nlog2n有常数)

#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
map <int,int> M[55];
int T,n;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
if(M[T][x])
{
continue;
}
M[T][x]=1;
printf("%d ",x);
}
printf("\n");
}
return 0;
}

bzoj AC,luogu TLE3个点

难道是卡常???

换!

②:挂链

利用类似挂链hash的方法,先对整数值取模再挂链查找即可

时间复杂度O(n)(常数不小)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define seed 13151
using namespace std;
map <int,int> M[55];
struct Edge
{
int next;
int to;
}edge[50005];
int head[14000];
int cnt=1;
void init()
{
memset(head,-1,sizeof(head));
memset(edge,0,sizeof(edge));
cnt=1;
}
void add(int l,int r)
{
edge[cnt].next=head[l];
edge[cnt].to=r;
head[l]=cnt++;
}
bool check(int v1,int v2)
{
for(int i=head[v1];i!=-1;i=edge[i].next)
{
int to=edge[i].to;
if(to==v2)
{
return 0;
}
}
return 1;
}
int T,n;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
init();
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
if(!check(x%seed,x))
{
continue;
}
add(x%seed,x);
printf("%d ",x);
}
printf("\n");
}
return 0;
}

luoguAC,bzoj TLE...

其实还有

③:离散化之后直接数组hash

时间复杂度O(nlog2n),瓶颈在于排序,但常数较小

没做尝试...

bzoj 2761的更多相关文章

  1. BZOJ 2761: [JLOI2011]不重复数字 水题

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2100  Solved: 809 题目连接 http:// ...

  2. bzoj 2761 [JLOI2011]不重复数字(哈希表)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3210  Solved: 1186[Submit][Sta ...

  3. bzoj 2761: [JLOI2011]不重复数字 (map||Treap)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2761 思路: map标记 实现代码: #include<bits/stdc++.h&g ...

  4. BZOJ 2761 不重复数字 set

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2761 题目大意: 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出 ...

  5. 【BZOJ 2761】 不重复数字 (哈希算法)

    链接 http://www.lydsy.com/JudgeOnline/problem.php?id=2761 Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如, ...

  6. bzoj 2761: [JLOI2011]不重复数字

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...

  7. bzoj 2761 平衡树

    裸地平衡树,只需要用到find操作 /**************************************************************     Problem:     U ...

  8. BZOJ 2761 不重复数字 (Hash)

    题解:直接使用STL中的hash去重即可 #include <cstdio> #include <map> using namespace std; int ans[50010 ...

  9. BZOJ 2761: [JLOI2011]不重复数字 hash哈希

    题目就不贴了 点我看题 题意:这题题意很简明,就是给一个序列,把序列里相同的删掉,然后输出,按原数列顺序. 思路:这题之前QZZ和ZN大神犇叫我去做,辣时还不会hash,就留着了.最近某夏令营学会了h ...

随机推荐

  1. 1.2MyBatis介绍

    MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis,实质上 ...

  2. ubuntu14.04升级mysql5.5至mysql5.7

    原文链接:https://www.cnblogs.com/os-python/p/6842485.html 1.下载mysql-apt的配置包,并安装 wget https://dev.mysql.c ...

  3. 如何能让MAC和PC都能读写移动硬盘

    Macbook Pro 移动硬盘 希捷硬盘就不用,有专业适用于苹果的软件. 1.在“LaunchPad”中找到并打开“磁盘工具”,在“磁盘工具”中可以看到移动硬盘的几个分区 2.选择一个分区后,选择“ ...

  4. 应急响应-GHO提取注册表快照

    前言 备份文件.gho中找到机器的注册表 文件夹位置 在 C:\WINDOWS\SYSTEM32\CONFIG 下就是系统的注册表,一般情况下,这里面会有以下几个文件: default 默认注册表文件 ...

  5. CVE-2019-0797漏洞:Windows操作系统中的新零日在攻击中被利用

    https://securelist.com/cve-2019-0797-zero-day-vulnerability/89885/ 前言 在2019年2月,卡巴实验室的自动漏洞防护(AEP)系统检测 ...

  6. Python3-线程

    线程 什么是线程 线程的创建开销小 线程与进程的区别 为何要用多线程 多线程的应用举例 开启线程的两种方式 在一个进程下开启多个线程与在一个进程下开启多个子进程的区别 多线程并发的socket服务器 ...

  7. workqueue --最清晰的讲解

    带你入门: 1.INIT_WORK(struct work_struct *work, void (*function)(void *), void *data) 上面一句只是定义了work和work ...

  8. http://nancyfx.org + ASPNETCORE

    商务产品servicestack:  https://servicestack.net/ http://nancyfx.org  +  ASPNETCORE http://nancyfx.org    ...

  9. HAProxy详解(二):HAProxy基础配置与应用实例

    一.HAProxy基础配置与应用实例: 1.快速安装HAProxy集群软件: HAProxy的官网: https://www.haproxy.org/#down下载HAProxy的源码包. 安装: [ ...

  10. 用vue+element-ui开发后台笔记

    1.前端通过 formData: new FormData(), 构造对象传数值给后台! 当传给后台的参数中有图片的时候,需要把需要传输的数据通过构造对象new FormData()的形式存数据,并且 ...