bzoj 2761
神题...
其实这题巨水,用各种诡异的方法都能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的更多相关文章
- BZOJ 2761: [JLOI2011]不重复数字 水题
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2100 Solved: 809 题目连接 http:// ...
- bzoj 2761 [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3210 Solved: 1186[Submit][Sta ...
- bzoj 2761: [JLOI2011]不重复数字 (map||Treap)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2761 思路: map标记 实现代码: #include<bits/stdc++.h&g ...
- BZOJ 2761 不重复数字 set
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2761 题目大意: 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出 ...
- 【BZOJ 2761】 不重复数字 (哈希算法)
链接 http://www.lydsy.com/JudgeOnline/problem.php?id=2761 Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如, ...
- bzoj 2761: [JLOI2011]不重复数字
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...
- bzoj 2761 平衡树
裸地平衡树,只需要用到find操作 /************************************************************** Problem: U ...
- BZOJ 2761 不重复数字 (Hash)
题解:直接使用STL中的hash去重即可 #include <cstdio> #include <map> using namespace std; int ans[50010 ...
- BZOJ 2761: [JLOI2011]不重复数字 hash哈希
题目就不贴了 点我看题 题意:这题题意很简明,就是给一个序列,把序列里相同的删掉,然后输出,按原数列顺序. 思路:这题之前QZZ和ZN大神犇叫我去做,辣时还不会hash,就留着了.最近某夏令营学会了h ...
随机推荐
- BigDecimal实现末尾去掉无用0
BigDecimal 原生提供了 stripTrailingZeros 方法可以实现去掉末尾的 0,然后使用 toPlainString 可以输出数值,注意这里如果使用 toString() 会变成 ...
- Python笔记(三)继承和多态、动态语言
一.继承 先定义一个A类 class A(object): def fun(self): print "Run A fun()" 在定义一个B类 class B(A): pass ...
- openstack Q版部署-----Mysql、MQ、Memcached安装配置(2)
一.安装mysql(contorller) 安装软件包: yum install -y mariadb mariadb-server python2-PyMySQL 配置my.cnf文件 vi /et ...
- hsf
参考文章: ----- 架构和框架的区别 1.HSF源码剖析 2.Http和RPC区别 3.分布式服务框架HSF 4.高并发架构系列:如何从0到1设计一个类Dubbo的RPC框架 5.HSF的原理分析 ...
- com.nostra13.universalimageloader 加载displayImage图片时图片模糊的处理办法
配置显示参数: DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(defaultR ...
- [转] pytorch指定GPU
查过好几次这个命令,总是忘,转一篇mark一下吧 转自:http://www.cnblogs.com/darkknightzh/p/6836568.html PyTorch默认使用从0开始的GPU,如 ...
- 华为Qinq的配置
作者:邓聪聪 qinq(dot1q in dot1q)是一种二层环境中的二层vpn技术,用于二层ISP网络将相同客户网络中的vlan帧,再打一层vlan-tag的手段实现同一个客户的不同站点之间的数据 ...
- boost.asio包装类st_asio_wrapper开发教程(一)
一:什么是st_asio_wrapper它是一个c/s网络编程框架,基于对boost.asio的包装(最低在boost-1.49.0上调试过),目的是快速的构建一个c/s系统: 二:st_asio_w ...
- Linux目录结构以及文件操作
Linux目录结构 UNIX 是以目录为主的,Linux 也继承了这一优良特性. Linux 是以树形目录结构的形式来构建整个系统的,可以理解为树形目录是一个用户可操作系统的骨架.虽然本质上无论是目录 ...
- https openssl http2
2018-3-21 10:27:45 星期三 参考: 对https, http2的解释 总结: 生成自有证书(非第三方证书颁发公司) 我使用的是gitbash工具, 命令为: $ openssl re ...