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 ...
随机推荐
- 2017-2018-2 20165330实验二《Java面向对象程序设计》实验报告
实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步骤 (一)单元测试 三种代码 伪代码:从意图层面来解 ...
- Apache Kafka Replication Design – High level
参考,https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Replication Kafka Replication High-level ...
- good blog
https://blog.csdn.net/fgf00/article/details/52793739
- OCR技术浅探:特征提取(1)
研究背景 关于光学字符识别(Optical Character Recognition, 下面都简称OCR),是指将图像上的文字转化为计算机可编辑的文字内容,众多的研究人员对相关的技术研究已久,也有不 ...
- @FindBy、@FindBys、@FindAll的区别
原文地址http://blog.csdn.net/tea_wu/article/details/21080789 selenium-webdriver中获取页面元素的方式有很多,使用注解获取页面元素是 ...
- listview与adapter用法
Android listview与adapter用法 listview与adapter用法 博客分类: android 一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用 ...
- [HZNUOJ] 博
Description 定义一个数字序列为“非下降序列”: 此处我们约定用$n\;表示数字序列的长度,下面定义在n \in [1, \infty]时有效$ $if \;\; n = 1:$ $\;\; ...
- 开源一款android 偷拍 app【静拍】豌豆荚、flyme商店已经上线
首先先花3秒时间,预览下下app的大概是做啥的,解决啥痛点的:) app: 本地下载地址 需求点: 1:音量键可以拍照 2:没有快门声.闪光灯 3:锁屏下.或者是在其他程序界面都可以拍照 思路: 1: ...
- Druid学习之路 (五)Druid的数据摄取任务类型
作者:Syn良子 出处:https://www.cnblogs.com/cssdongl/p/9885534.html 转载请注明出处 Druid的数据摄取任务类型 Druid支持很多种类型的数据摄取 ...
- Webpack+React+ES6 最新环境搭建和配置(2017年)
刚刚学习React,发现React在ES6下的语法才是本体,结合ES6新的语言特性,使组件化开发显得更加直观.而且现在的Angular2也开始使用支持强类型的TypeScript,转译(transpi ...