[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 ...
随机推荐
- NPOI导入excel文件为DataTable,使用SqlBulkCopy添加到数据库表
public DataTable ExcelToDataTable(Stream stream, string fileName) { DataTable data = new DataTable() ...
- 小程序学习一 .json 文件配置
微信小程序——配置 以下就是小编对小程序配置的资料进行的系统的整理,希望能对开发者有帮助. 我们使用app.json文件来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置 ...
- 将.db文件导入SQLServer2008数据库
最近要做一个项目,需要连接数据库,给我的数据文件是sqlite,我需要将数据导入到SQLServer数据库 需要借助一个软件:DBDBMigration 页面最上方的选择框内,先选择数据文件类型,这里 ...
- mysql Percona-XtraBackup backup
全量备份FULL BACKUP https://www.percona.com/doc/percona-xtrabackup/2.4/backup_scenarios/full_backup.html ...
- idea创建web聚合工程(2)
参考文档: intelj idea 创建聚合项目(典型web项目,包括子项目util.dao.service) 使用IntelliJ IDEA创建Maven聚合工程.创建resources文件夹.ss ...
- SpringBoot简单的REST风格例子
关于REST和RESTful的说明请移步至:怎样用通俗的语言解释REST,以及RESTful? 其实我自己也不是十分的理解,只是今天学SpringBoot时看到有个标着REST风格的简单例子,就记录一 ...
- 使用pipeline减少与redis交互次数
1.redis_pipeline=redis_cli.pipeline() 2.redis_pipeline.setex()此语句可写多条 3.redis_pipeline.execute() # # ...
- Oracle简介
1.Oracle 数据库基于客户端/服务 2. Oracle认证 OCA:Oracle认证助理工程师,比较简单 OCP:Oracle认证专家 OCM:Oracle认证资深专家 3.Oracle 服务的 ...
- 使用@JsonFormat引起的时间比正常时间慢8小时解决方法
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
- 了解java中垃圾回收机制
Java的垃圾回收机制是Java环境自带有的,它不像c语言的malloc申请空间后需要Free()函数来释放,而Java中的代码块中所申请的空间可在程序执行完成后自动释放,但是是有局限性的,代码块所占 ...