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 ...
随机推荐
- nmap 使用总结
nmap 网络探测工具 参考链接: https://nmap.org/man/zh/ http://www.360doc.com/content/18/0127/18/52402560_7255744 ...
- 用v-for进行table循环
<table class="mytable mt10"> <template v-for="(item,index) in device_fault&q ...
- Light oj 1018 - Brush (IV) 状态压缩
题目大意: 给出n个点的坐标,求至少画多少掉直线才能连接所有点. 题目思路:状态压缩 首先经行预处理,求出所有状态下,那些点不在该状态内 以任意两点为端点求出这条直线的状态 枚举所有状态,找出不在当前 ...
- centos设置服务开机启动失败问题
1.安装某服务设置开机启动的时候报错 [root@node1 ~]# systemctl enable lvm2-lvmetad.serviceThe unit files have no [Inst ...
- 2016521-Java-第八周学习总结
课本知识点 start() run()定义线程线程对象被调度之后所执行的操作 -sleep(int millsecond),必须在try-catch语句块中调用sleep方法 sAlive() 线程同 ...
- ORA-03113: end-of-file on communication channel 磁盘慢,数据库启动失败
磁盘慢,数据库启动失败:解决思路:1.让数据文件offline: 2.删除表空间 SQL> startup pfile='/server/oracle/admin/test/pfile/init ...
- 为Oracle GoldenGate准备数据库
了解如何为Oracle GoldenGate准备数据库,包括如何配置连接和日志记录,如何在数据库中启用Oracle GoldenGate,如何设置闪回查询以及如何管理服务器资源. 为集成进程配置连接 ...
- 统计分析与R软件-chapter2-3
2.3 对象和它的模式与属性 R是一种基于对象的语言,R的对象包含了若干个元素作为其数据,另外还可以有一些特殊数据称为属性,并规定了一些特定操作(如打印.绘图).比如,一个向量是一个对象,一个图形也是 ...
- Centos下配置php环境
Centos下配置php环境 目录[-] 环境: GD2 2 安装PHP 5.2.14(FastCGI模式) 1)编译安装PHP 5.2.14所需的支持库: 2)编译安装MySQL 5.5.3-m ...
- gnutls-3.5.18 static building for windows
gnutls-3.5.18 static building for windows Required libraries:1. libnettle 2. gmplib Optional librari ...