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
题意就是找相等的数,输出第二个的位置,可是要是最先发现的。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> using namespace std; #define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, m) for(int i=1; i<=m; i++)
#define f3(i, n) for(int i=n; i>=0; i--)
#define M 1005 const int INF = 0x3f3f3f3f; int main()
{ int p, n, m, i;
int ans[M];
memset(ans, 0, sizeof(ans));
scanf("%d%d",&p,&n);
for (i=1; i<=n; i++)
{
scanf("%d",&m);
if (ans[m%p]++ == 1)
break;
}
printf("%d\n",(i>n)?-1:i); }

Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash的更多相关文章

  1. Codeforces Round #FF (Div. 2):C. DZY Loves Sequences

    C. DZY Loves Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #254 (Div. 2):A. DZY Loves Chessboard

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

  3. Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry

    B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  5. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  6. Codeforces Round #FF (Div. 2) 题解

    比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit p ...

  7. Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列

    B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...

  8. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划

    A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...

  9. Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列

    D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...

随机推荐

  1. (转)解析php中die(),exit(),return的区别

    本篇文章是对php中die(),exit(),return的区别进行了详细的分析介绍,需要的朋友参考下     die()停止程序运行,输出内容exit是停止程序运行,不输出内容return是返回值d ...

  2. Android中滑动关闭Activity

    继承SwipeBackActivity即可实现向右滑动删除Activity效果 点击下载所需文件

  3. jquery插件:点击拉出的右侧滑动菜单

    就是一个停留在页面右侧的滑动菜单,点击可以拉出,带回调函数.宽高位置可以参数指定.插件代码如下: (jquery的路径请自己修改) (function($){ $.fn.sideSwitch = fu ...

  4. oracle 使用 ALTER 操作列

    使用 ALTER TABLE 语句追加, 修改, 或删除列的语法

  5. 武汉科技大学ACM:1008: 明明的随机数

    Problem Description 明明想在学校中请一些同学一起做一项问卷 调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个, ...

  6. 你好,C++(13)这道单选题的答案是A、B、C还是D?3.7 枚举类型

    3.7  枚举类型 除了之前我们介绍的数值数据和文字数据之外,在现实世界中,常常还会遇到这样一类数据:一道单选题的答案只能是A.B.C.D四个选项中的某一个:红绿灯的颜色只能是红色,绿色和黄色中的某一 ...

  7. ADODB的应用

    <?php include_once ('adodb5/adodb.inc.php'); $db = NewADOConnection ('mysql'); $db->Connect(&q ...

  8. PDO封装函数

    header("Content-type: text/html; charset=utf-8"); /** * 初始化 pdo 对象实例 * @param bool $newins ...

  9. Destoon后台修改公司会员资料信息的必填项限制修改

    /template/default/member/edit.htm module\member\admin\template\member_edit.tpl.php module\member\adm ...

  10. cocos2d(粒子效果编辑器)

    ParticleDesigner  for  Mac下载地址:http://www.cocoachina.com/bbs/read.php?tid=108339 最近在做一款粒子编辑器 其实就是在co ...