[CodeForces - 447A] A - DZY Loves Hash
A - DZY Loves Hash
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert nnumbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b.
However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1.
Input
The first line contains two integers, p and n (2 ≤ p, n ≤ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≤ xi ≤ 109).
Output
Output a single integer — the answer to the problem.
Example
10 5021534153
4
5 501234
-1
题目的意思是,按顺序给出几个数,判断从哪个操作开始,hash值有重复.
题目很水,模拟一下就好了.
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; int main(){ int n,m; scanf("%d%d",&m,&n); ; i<=n; i++){ int x; scanf("%d",&x); x%=m; ;} vis[x]=; } puts("-1"); ; }
[CodeForces - 447A] A - DZY Loves Hash的更多相关文章
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF A. DZY Loves Hash
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 444 C - DZY Loves Colors
C - DZY Loves Colors 思路: 分块,复杂度有点玄学,和普通分块不同的是在这个块被一次染色的时候暴力染整个块. 代码: #pragma GCC optimize(2) #pragma ...
- [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
E DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ...
- [CodeForces - 447D] D - DZY Loves Modification
D - DZY Loves Modification As we know, DZY loves playing games. One day DZY decided to play with a n ...
- [CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...
- [CodeForces - 447B] B - DZY Loves Strings
B - DZY Loves Strings DZY loves collecting special strings which only contain lowercase letters. For ...
- D - DZY Loves Hash CodeForces - 447A
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...
随机推荐
- node.js模块本地代理模块(将自己本机/局域网)服务 代理到外网可以访问
npm 模块 localtunnel模块可以. lt --port 7000 其中7000是本地服务端口 会分配一个动态的url. 局域网中查看本地ip用ifconfg 或者在系统偏好设置里面查看网 ...
- ngui处理不规则按钮点击
吐个槽 棋牌类游戏做什么中国地图!!! 然后就要用到不规则按钮点击了 你懂的 213的unity虽然已经加入了polygoncollider 2d的支持 但是 但是 但是 是2d的 也就是说如果不 ...
- 删除node_modules文件
删除node_modules文件夹报错:路径太长,无法删除. npm install rimraf -g rimraf node_modules
- Easyui使用心得(1)--DateGrid表格
最近一直在用easyui这个控件,有一点心得,在这里和大家分享一下,也是对自己工作的一个小小的总结,希望可以形成一个完整的Easyui的笔记体系,可以方便更多的人 因为自己也是在摸索中前进,难免有遗漏 ...
- python 定时器
2s启动一个定时器: import threading import time def hello(name): print "hello %s\n" % name global ...
- 如何将购物车信息存到Redis中?
存到Redis中,好处是速度快.毕竟写到硬盘需要更多的时间.加入购物车的功能,操作很频繁,可以通过Redis快速写入,移除,修改. 用什么方式呢? 传统的KEY,VALUE不太合适,每次增加修改,都要 ...
- typeScript入门基础 (1)
1.ts是js的超集,可使用es5,es6的代码 2. ts的安装与编译: a. 首先需要Node.js环境 . 相信都有,略过. 不会的请百度,或者留言. b. npm install - ...
- 在vscode中,自定义代码片段,例vue组件的模板
1---- 2---- 输入vue, 选 vue.json 3---- 在vue.json中编辑, 有说明 a. tab符,要用空格, 也可以转义 4---- 新建vue文件, 输入自定义 ...
- 学习笔记35—大话 Word和Excel
1.word中,加粗表格线条:设计---->笔画粗细. 2.Excel中,冻结某一行:点击工具栏中的视图→冻结空格→冻结单元格. 3.word中,输入卡方符号:插入----> 符号 --- ...
- 学习笔记24—win10环境下python版libsvm的安装
1.前言 由于毕业设计需要用到libsvm,所以最近专心于配置libsvm,曾经尝试过在matlab中安装,但是没有成功.最终在Python环境中完成安装. 2.LIBSVM介绍 LIBSVM 是台湾 ...