A. DZY Loves Hash
来源:互联网 发布:淘宝上买iphone店铺 编辑:程序博客网 时间:2024/04/30 07:01
DZY has a hash table with p buckets, numbered from0 top - 1. He wants to insertn numbers, in the order they are given, into the hash table. For thei-th numberxi, DZY will put it into the bucket numberedh(xi), whereh(x) is the hash function. In this problem we will assume, thath(x) = x mod p. Operationa mod b denotes taking a remainder after divisiona 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 thei-th insertion, you should output i. If no conflict happens, just output-1.
The first line contains two integers, p andn(2 ≤ p, n ≤ 300). Thenn lines follow. Thei-th of them contains an integer xi(0 ≤ xi ≤ 109).
Output a single integer — the answer to the problem.
10 5021534153
4
5 501234
-1
//水题不多说
//AC代码
#include<iostream>#include<queue>#include<algorithm>#include<cstdio>#include<cstring>#include<string>#include<map>using namespace std;int main(){ int p,n,x,y,j; int z[301]; //while(1) //{ cin>>p>>n; map<int,int>Map; memset(z,0,sizeof(z)); j=0; for(int i=1;i<=n;i++) { cin>>x; y=x%p; Map[y]+=1; if(Map[y]>1) { z[j++]=i; } } if(j!=0) { cout<<z[0]<<endl; } else cout<<-1<<endl; //} return 0;}
- A. DZY Loves Hash
- A. DZY Loves Hash
- CF A. DZY Loves Hash
- Codeforces 447A DZY Loves Hash
- cf-#FF-A-DZY Loves Hash
- CodeForces 447-A. DZY Loves Hash
- CodeForces 447A DZY Loves Hash
- CodeForces 447A DZY Loves Hash
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- CF 447A(DZY Loves Hash-简单判重)
- Codeforces Round #FF (Div. 2)A. DZY Loves Hash
- Codeforces Round #FF (Div. 2)A. DZY Loves Hash
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
- A. DZY Loves Chessboard
- A. DZY Loves Chessboard
- http://www.cnblogs.com/end/archive/2012/09/25/2701486.html
- ASP.NET MVC Model验证(五)
- C/C++与Matlab混合编程初探
- 编程算法 - 圆圈中最后剩下的数字(递推公式) 代码(C++)
- UVA 23 out of 5
- A. DZY Loves Hash
- Windows中.exe程序的启动过程和C/C++运行时库
- poj 1523 tarjan求割点
- 由《小道消息 • 思维偏误》说开来。
- MATLAB 与 PostgreSQL 数据库的连接
- poj-1961-Period
- 一个microsoft的.exe程序文件的启动过程 .
- UVALive 6469 Deranged Exams 组合数学+容斥原理
- 思考,领悟,前进