博客
关于我
Lougu P1102 A-B 数对【hash】
阅读量:354 次
发布时间:2019-03-04

本文共 568 字,大约阅读时间需要 1 分钟。

在这里插入图片描述

这道题其实暴力很简单。
但是!我就要用hash做!

#include
#include
#include
#define p 4000037using namespace std;long long a[p],b[200010],c[p];long long n,C,x,qm,ans;long long hash(long long x){ return x%p;}long long dw(long long x){ long long j=0; qm=hash(abs(x)); while(a[hash(j+qm)]!=x&&c[hash(j+qm)]!=0) j++; return hash(j+qm);}int main(){ scanf("%lld%lld",&n,&C); for(int i=1; i<=n; i++) { scanf("%lld",&b[i]); a[dw(b[i])]=b[i]; //一个存 数,一个存 数的次数 c[dw(b[i])]++; } for(int i=1; i<=n; i++) ans+=c[dw(b[i]-C)%p]; //统计 cout<

转载地址:http://gsle.baihongyu.com/

你可能感兴趣的文章
NEW DATE()之参数传递
查看>>
New Relic——手机应用app开发达人的福利立即就到啦!
查看>>
new 一个button 然后dispose,最后这个button是null吗???
查看>>
Next.js React Server Components 教程
查看>>
next项目部署到服务器pm2进程守护
查看>>
nexus 介绍
查看>>
nexus上传jar
查看>>
Nexus指南中的更新强调集成和透明度的重要性
查看>>
Nexus指南已经发布
查看>>
Nexus(1):Nexus的安装与配置
查看>>
NFinal学习笔记 02—NFinalBuild
查看>>
NFS
查看>>
nfs mount 故障 mount.nfs: access denied by server while mounting 10.0.100.208:/backup_usb
查看>>
NFS Server及Client配置与挂载详解
查看>>
NFS 服务配置篇
查看>>
NFS共享文件系统搭建
查看>>
nfs复习
查看>>
NFS安装配置
查看>>
NFS服务器配置-服务启动与停止
查看>>
NFS的安装以及windows/linux挂载linux网络文件系统NFS
查看>>