A. DZY Loves Hash
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Sample test(s)
Input
10 5
0
21
53
41
53
Output
4
Input
5 5
0
1
2
3
4
Output
-1

//题意就是找相等的数,输出第二个的位置,可是要是最先发现的。
比如:10 5
1 2 2 2 1
输出是3而不是5,由于先找到2和2相等,假设仅仅用for循环,找到的是1和1相等输出是5.
第4个例子卡了非常久,没看懂题目。 。。。
#include <iostream>
using namespace std;
int main()
{ __int64 a[400];
int n,t,i,j,p,k;
while(scanf("%d%d",&p,&n)!=EOF)
{ memset(a,0,sizeof(a));
t=0;
for(i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
a[i]=a[i]%p;
}
k=n;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
k=k<(j+1)? k:(j+1);
t=1;
} }
if(t==1)
printf("%d\n",k);
if(t==0)
printf("-1\n");
}
return 0;
}

CF A. DZY Loves Hash的更多相关文章

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

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

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

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

  4. CF 444C DZY Loves Physics(图论结论题)

    题目链接: 传送门 DZY Loves Chemistry time limit per test1 second     memory limit per test256 megabytes Des ...

  5. CF 445B DZY Loves Chemistry(并查集)

    题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second     memory limit per test:256 megabytes D ...

  6. CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)

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

  7. CF 444B(DZY Loves FFT-时间复杂度)

    B. DZY Loves FFT time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. Cf 444C DZY Loves Colors(段树)

    DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consi ...

  9. CF 445A(DZY Loves Chessboard-BW填充)

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. Windbg调试Sql Server 进程

    http://blog.csdn.net/bcbobo21cn/article/details/52261466 http://www.sqlservercentral.com/blogs/asche ...

  2. flask的安全注意事项,如何防范XSS、CSRF、JSON安全

    参考官方文档:http://docs.jinkan.org/docs/flask/security.html 1.xss Flask 配置 Jinja2 自动转义所有值,除非显式地指明不转义.这就排除 ...

  3. [资料分享]GIS+=地理信息+云计算+大数据+容器+物联网+...论文、会议、讲座资料分享

    分享地址 http://pan.baidu.com/s/1gesDSB5 部分内容截图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5 ...

  4. 一张图,关于 Bayes error rate,贝叶斯错误率等的分析

    造轮子是那帮搞研究的“科学家”干的事情(类似E&E里的explore),“工程师”的职责是利用已有的东西解决问题(类似E&E里的exploit). 其次,即使以工程师的角色解决业务问题 ...

  5. 分布式数据库中间件–(1) Cobar初始化过程

    Cobar-Server的源代码地址:GitHub 欢迎Fork. 官方文档描写叙述Cobar的网络通信模块见下图. Cobar使用了Java的NIO进行处理读写.NIO是Java中的IO复用.而不须 ...

  6. Sereja and Array-数组操作或者线段树或树状数组

    CodeForces - 315B Sereja and Array Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I ...

  7. C# DataTable 总结

    (1)构造函数 DataTable()   不带参数初始化DataTable 类的新实例. DataTable(string tableName)  用指定的表名初始化DataTable 类的新实例. ...

  8. iPhone X

    iPhone X前置深度摄像头带来了Animoji和face ID,同时也将3D Face Tracking的接口开放给了开发者.有幸去Cupertino苹果总部参加了iPhone X的封闭开发,本文 ...

  9. Redis源码试读(一)源码准备

    这里开始查看Redis的源码,之前是在看Unix的环境编程,虽然这本书写的很好,但是只看这个感觉有点隔靴搔痒.你可以知道沙子.水泥.钢筋的特性,但是要想建一栋大楼仍然是另一回事.Unix环境编程要看, ...

  10. Tsung 初步介绍安装

    tsung是erlang的一个开源的一个压力测试工具,可以测试包括HTTP, WebDAV, Mysql, PostgreSQL, LDAP, and XMPP/Jabber等服务器.针对 HTTP ...