BZOJ 2761: [JLOI2011]不重复数字 hash哈希
题目就不贴了
题意:这题题意很简明,就是给一个序列,把序列里相同的删掉,然后输出,按原数列顺序。
思路:这题之前QZZ和ZN大神犇叫我去做,辣时还不会hash,就留着了。最近某夏令营学会了hash就回来写。
就是很简单的hash裸题。
我的hash就是把数字的每一位加起来然后累乘再膜。
从夏令营中涨了姿势,hash可以选择不判重,然后直接通过多hash的方法减少碰撞概率。
QAQ...刚开始以为3hash就够了,最后5hash才水过去。QAQ注意输出格式,行末没空格。
const
base1=;
base2=;
base3=;
base4=;
base5=;
QZZ=; //膜神犇RP++
HR=;//膜神犇RP++
TJM=;//膜神犇RP++
ZN=;//膜神犇RP++
HJW=;//膜神犇RP++
var n:longint;
s:string;
num:longint;
a:array[..]of longint;
i,j,x,y,k:longint;
hash1,hash2,hash3,hash4,hash5:int64;
v1,v2,v3,v4,v5:array[..,..]of boolean;
bool:integer;
t,qaq:longint;
begin
read(t);
for qaq:= to t do
begin
read(n);
for i:= to do
for j:= to do
begin
v1[i,j]:=false;
v2[i,j]:=false;
v3[i,j]:=false;
v4[i,j]:=false;
v5[i,j]:=false;
end;
num:=;
for i:= to n do
begin
read(x);
if x>= then bool:= else
begin
bool:=;
x:=-x;
end;
str(x,s);
if bool= then x:=-x;
hash1:=;
hash2:=;
hash3:=;
hash4:=;
hash5:=;
for j:= to length(s) do
begin
hash1:=(hash1*base1+ord(s[j])) mod QZZ;
hash2:=(hash2*base2+ord(s[j])) mod HR;
hash3:=(hash3*base3+ord(s[j])) mod TJM;
hash4:=(hash4*base4+ord(s[j])) mod ZN;
hash5:=(hash5*base5+ord(s[j])) mod HJW;
end;
if (not v1[bool][hash1]) then
begin
v1[bool][hash1]:=true;
v2[bool][hash2]:=true;
v3[bool][hash3]:=true;
v4[bool][hash4]:=true;
v5[bool][hash5]:=true;
inc(num);
a[num]:=x;
end else
if (not v2[bool][hash2]) then
begin
v2[bool][hash2]:=true;
v3[bool][hash3]:=true;
v4[bool][hash4]:=true;
v5[bool][hash5]:=true;
inc(num);
a[num]:=x;
end else
if (not v3[bool][hash3]) then
begin
v3[bool][hash3]:=true;
v4[bool][hash4]:=true;
v5[bool][hash5]:=true;
inc(num);
a[num]:=x;
end else
if (not v4[bool][hash4]) then
begin
v4[bool][hash4]:=true;
v5[bool][hash5]:=true;
inc(num);
a[num]:=x;
end else
if (not v5[bool][hash5]) then
begin
v5[bool][hash5]:=true;
inc(num);
a[num]:=x;
end;
end;
for i:= to num- do
write(a[i],' ');
writeln(a[num]);
end;
end.
hash
BZOJ 2761: [JLOI2011]不重复数字 hash哈希的更多相关文章
- 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:// ...
- 2761: [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1770 Solved: 675[Submit][Stat ...
- bzoj 2761: [JLOI2011]不重复数字【hash】
map会T,双hash会冲突--于是非酋写了个三hash #include<iostream> #include<cstdio> #include<cstring> ...
- 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]不重复数字 (map||Treap)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2761 思路: map标记 实现代码: #include<bits/stdc++.h&g ...
- bzoj 2761: [JLOI2011]不重复数字
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #d ...
- 【BZOJ 2761】 不重复数字 (哈希算法)
链接 http://www.lydsy.com/JudgeOnline/problem.php?id=2761 Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如, ...
- 2761: [JLOI2011]不重复数字(平衡树)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2133 Solved: 825[Submit][Stat ...
随机推荐
- Gartner提出的7种多租户模型
下面,我们就来看看在SaaS应用搭建过程中,可以采用什么样的多租户模型.从而能较为清晰地了解未来使用PaaS平台开发的SaaS,可以为用户提供哪些多租户的服务. Gartner提出了7种 ...
- Storm-源码分析- Messaging (backtype.storm.messaging)
先定义两个接口和一个类 TaskMessage类本身比较好理解, 抽象storm的message格式 对于IContext, 注释也说了, 定义messaging plugin, 通过什么渠道去发送m ...
- Linux命令(基础1)
一 命令的基本构成 (PS:Linux发行版本命令大概有200多个,熟练掌握个百八的就行了,其余的有个大概了解) 命令体 选项 参数(对象) ls -l /var 1.1参数:文件 文件类型: d ...
- 1. testNG+Maven 环境搭建
一:使用的工具 : TestNG 6.9.10 Maven 3.5 IDEA 二:创建maven项目,在pom.xml添加依赖 <?xml version="1.0" enc ...
- 除去DataTable中的空行!
昨天向数据库中导入Excel数据时 由于空行 总是报错!下面附上两种去除空行的方法! 方法一.某行某列值为空时 DataView dv = dt.DefaultView; ...
- Spark2.0机器学习系列之12: 线性回归及L1、L2正则化区别与稀疏解
概述 线性回归拟合一个因变量与一个自变量之间的线性关系y=f(x). Spark中实现了: (1)普通最小二乘法 (2)岭回归(L2正规化) (3)La ...
- .globl分析
Uboot中常看到.globl .globl _start _start: b reset .align .globl _TEXT_BASE _TEXT_BASE: .globl _start /* ...
- django后台数据管理admin设置代码
新建admin用户 createsuperuser 设定好用户名,邮箱,密码 设置setting LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shangha ...
- 记录:python读取excel文件
由于最近老是用到python读取excel文件,所以特意记录一下python读取excel文件的大体框架. 库:xlrd(读),直接pip安装即可.想要写excel文件的话,安装xlwd库即可,也是直 ...
- 20165324 《Java程序设计》第九周学习总结
学号 20165324 <Java程序设计>第九周学习总结 教材学习内容总结 第十三章 Java网络编程 URL类 使用URL创建对象的应用程序称为客户端 一个URL对象封装一个具体资源的 ...