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 ...
随机推荐
- android sdk 中跨平台部分
跨平台部分: platforms samples sources system-images 这几个可以直接拷贝即可
- webpack4学习笔记(一)
webpack4 1,安装webpack npm insatll webpack --save-dev //安装最新版本 npm insatll webpack@<version> --s ...
- shell 从文件中读取批量文件名并做命令行操作
222文件内容: /home/zhangsuosheng/Desktop/9-30/9_30/1bak/1538291162.png /home/zhangsuosheng/Desktop/9-30/ ...
- Unity3D Quaternion各属性和函数測试
Quaternion属性与方法 一,属性: x.y.z就不说了,仅仅看一个eulerAngles.代码例如以下: public Quaternion rotation = Quaternion.ide ...
- OpenCV膨胀与腐蚀
膨胀与腐蚀 本篇博客主要介绍使用OpenCV中的函数接口实现对一个图片的腐蚀或者膨胀,听起来有点像是对图像进行放大和缩小的意思,如果你也是这样认为,那我只能说你跟我一样肤浅!!在OpenCV中几乎所有 ...
- 《闪存问题之PROGRAM DISTURB》总结
来自 http://www.ssdfans.com/?p=1814 SSD之所以需要BCH或LDPC等ECC纠错算法,是因为闪存中的数据会在神不知鬼不觉的情况下发生比特翻转. 导致比特翻转的原因很多, ...
- 元类 metaclass
metaclass 类由Type创建 对象由创建 MetaClass作用 用来指定当前类由谁来创建(默认type创建). MetaClass 会被继承,如果父类指定了元类,那么子类也是由这个元类创建 ...
- C# comport 打印图像
public string GetLogo() { string logo = ""; if (!File.Exists(@"C:\bitmap.bmp")) ...
- PHPCMS新闻内容调用方法介绍
{template "content","header"} ---------- 调用根目录下phpcms\template\content\header文件 ...
- koa2简单demo
// 导入koa,和koa 1.x不同,在koa2中,我们导入的是一个class,因此用大写的Koa表示: const Koa = require('koa'); const Router = req ...