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 ...
随机推荐
- 【jquery隐藏、显示事件and提示callback】【淡入淡出fadeToggle】【滑入滑出slideToggle】【动画animate】【停止动画stop】
1.jquery隐藏and显示事件 $("p").hide(); //隐藏事件$("p").hide(1000); //1秒内缓慢隐藏$(" ...
- I - Magic FZU - 2280 (字符串hash)
题目链接: I - Magic FZU - 2280 学习链接: FZU - 2280 I - Magic 题目大意: 给你nn个字符串,每个字符串有一个值ww,有qq次询问,一共两种操作:一是“1, ...
- iTOP-4418开发板Ubuntu系统烧写方法分享
开发平台:迅为iTOP-4418开发板 系统:Ubuntu 1. TF卡读写速度测试 烧写 Ubuntu 对于 TF 卡的要求比较高,很多老旧的卡都无法烧写 Ubuntu,下面提供一种 相对 ...
- 【转载】 python-星号变量的特殊用法
原文链接:https://www.qingsword.com/qing/python-12.html 引言 在Python中,星号除了用于乘法数值运算和幂运算外,还有一种特殊的用法"在变量前 ...
- 【转载】双调排序Bitonic Sort,适合并行计算的排序算法
双调排序是data-independent的排序, 即比较顺序与数据无关的排序方法, 特别适合做并行计算,例如用GPU.fpga来计算. 1.双调序列 在了解双调排序算法之前,我们先来看看什么是双调序 ...
- Mysql多实例安装笔记
参考: 系统:KaliLinux (x86_64) 软件下载 1.下载地址: 2.选择5.6版本 安装 1.准备文件和目录 tar -zxvf mysql-5.6.40-linux-glibc2.12 ...
- Shell-删除误解压的文件
我意外在/var/www/html/,而不是/home/projects/www/current下解压了一个tarball.它搞乱了/var/www/html下的文件,你甚至不知道哪些是误解压出来的. ...
- 记录一下putty的pscp的用法【转】
转自 记录一下putty的pscp的用法 - 刘荣星的博客 https://www.liurongxing.com/how-use-the-putty-and-pscp.html 以前一直用Secu ...
- MySQL log_slave_updates 参数【转】
说明:最近部署了mysql的集群环境,详细如下M01和M02为主主复制,M01和R01为主从复制:在测试的过程中发现了以下问题: 1.M01和M02的主主复制是没有问题的(从M01写入数据能同步到M0 ...
- windows命令行获取时间
在写Windows批处理脚本时,常常需要获取系统日期.时间戳记,用作文件名.文件夹名.log等等. 本文介绍了如何获取自订的系统日期.时间戳记. 首先,在Windows中,系统日期由以下参数获得: % ...