DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, 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

Input
10 5
0
21
53
41
53
Output
4
Input
5 5
0
1
2
3
4 题意:把n个数字放到0~p-1个位置,要求x放在x%p的位置;如果已经放过 输出x的位置,否则输出-1;
(吐槽一下这个题,一直wa就是找不到原因,最后发现原来是没有数组清零,真是太坑了;)
代码:
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std; int main(){
int n,p,k,flag=;
//char c[301][20];
char m[]; unsigned long long x;
cin>>p>>n;
for(int i = ;i<p;i++)
{
m[i]=;
}//数组一定要清零,
for(int i=;i<n;i++){
cin>>x;
k=x%p;
if(m[k]==)
m[k]=;
else if(!flag)
flag=i+;
}
if(flag)cout<<flag<<endl;
else cout<<-<<endl; }

 Output
-1

D - DZY Loves Hash CodeForces - 447A的更多相关文章

  1. [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 ...

  2. 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 ...

  3. CF A. DZY Loves Hash

    A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. 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 ...

  5. CF447A 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 ...

  6. DZY Loves Colors CodeForces - 444C (线段树势能分析)

    大意:有$n$个格子, 初始$i$位置的颜色为$i$, 美丽值为0, 有两种操作 将区间$[l,r]$内的元素全部改为$x$, 每个元素的美丽值增加$|x-y|$, $y$为未改动时的值 询问区间$[ ...

  7. Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs

    题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...

  8. CF 447A(DZY Loves Hash-简单判重)

    A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力

    D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...

随机推荐

  1. Spring Data Jpa(Hibernate) OneToMany

    这个其实非常简单.假设有topic 和 subscriber两个实体类,不考虑关联关系,则连个类的代码如下: /** * Created by csonezp on 2017/8/31. */ @En ...

  2. Bootstrap中的datetimepicker用法,只看一眼就全懂了

    本文实例为大家分享了bootstrap datetimepicker日期插件的简单使用,供大家参考,具体内容如下 首先在文件头部引入必要的文件: 1 2 <link rel="styl ...

  3. Nodejs进阶:服务端字符编解码&乱码处理

    写在前面 在web服务端开发中,字符的编解码几乎每天都要打交道.编解码一旦处理不当,就会出现令人头疼的乱码问题. 不少从事node服务端开发的同学,由于对字符编码码相关知识了解不足,遇到问题时,经常会 ...

  4. Keep in Mind

    Do not undermine your worth by comparing yourself with others.It is because we are different and eac ...

  5. js实现非模态窗口增加数据后刷新父窗口数据

    父窗口是由两个部分组成,一个html的table,一部分是extjs的gird. 点击grid面板[增加]按钮将会弹出非模态窗口进行新数据的编辑页面 下面是按钮的触发函数代码: var a = win ...

  6. Redis订阅和发布模式和Redis事务

    -------------------Redis订阅和发布模式------------------- 1.概念     Redis 发布订阅(pub/sub)是一种消息通信模式:     发送者(pu ...

  7. C++内存布局详解

    一个由C/C++编译的程序除了存放函数二进制代码的程序代码段(code段)外,数据占用的内存大致分为以下几个部分: 1.栈区(stack) 存放局部变量.函数参数.返回数据.返回地址等.系统自动分配释 ...

  8. iOS block和代理的区别

      block和代理是iOS开发中实现回调的两种方式,大多数情况下是用哪个都可以,主要看个人喜好.本文主要是对两者做一下对比. 1.block简介   在 iOS中, block一共分三种.   (1 ...

  9. 带你简单了解python协程和异步

    带你简单了解python的协程和异步 前言 对于学习异步的出发点,是写爬虫.从简单爬虫到学会了使用多线程爬虫之后,在翻看别人的博客文章时偶尔会看到异步这一说法.而对于异步的了解实在困扰了我好久好久,看 ...

  10. 201521123082 《Java程序设计》第13周学习总结

    201521123082 <Java程序设计>第13周学习总结 标签(空格分隔): java 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. ...