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 ...
随机推荐
- Linux压缩解压缩(unzip,tar)
unzip tar 常用解压缩命令: tar -zxvpf:解压缩 tar -zcvpf: 压缩 # tar [-j|-z] [cv] [-f 建立的檔名] filename... <==打包与 ...
- webservice接口问题:Payload: No message body writer has been found for class domain, ContentType: application/xml
当在使用cxf-rs的webservice的时候,有时候在传输数据,会发生这种错误 错误代码: Response-Code: 500 Content-Type: text/plain Headers: ...
- 多线程入门-第六章-线程的调度与控制之join
/* 线程合并:将指定的线程加入到当前线程,可以将两个交替执行的线程合并为顺序执行的线程,即单线程. 如在B线程中调用了A的join方法,则线程A执行完后,才会执行线程B. */ public cla ...
- ActiveMQ 详解
1. 如何同步索引库 方案一: 在taotao-manager中,添加商品的业务逻辑中,添加一个同步索引库的业务逻辑; 缺点:业务逻辑耦合度高,业务拆分不明确; 方案二: 业务逻辑在taotato-s ...
- 自定义HTTP头时的注意事项(转)
原文:https://blog.gnuers.org/?p=462 HTTP头是可以包含英文字母([A-Za-z]).数字([0-9]).连接号(-)hyphens, 也可义是下划线(_).在使用ng ...
- django迁移:全局、局部
django迁移:全局.局部 django 数据库迁移(migrate)应该知道的一些事 https://blog.csdn.net/stonesola/article/details/6975861 ...
- 发现一个小技巧:火狐浏览器对phpmyadmin支持更友好
这段时间ytkah正在迁移服务器(A→B),为了方便起见,直接用phpmyadmin导入数据库.一般我们是用navicat来操作数据库的,但是服务器A设置了权限,无法用navicat连接,只好在浏览器 ...
- 图书源代码下载: Modern Differential Geometry of CURVES and SURFACES with Mathematica
http://alpha01.dm.unito.it/personalpages/abbena/gray/ Contents 1. Curves in the Plane | 2. Famou ...
- java 多线程 day09 线程池
import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.c ...
- gui设计
芯艺,你好! ... ... ... 芯艺,再见! http://www.chipart.cn/ 附件 http://files.cnblogs.com/files/dong1/%E8%89%BA%E ...