水题。题目大意为输入一个p,n,再输入n组数据,每组数据对p取余,当和前面相同时,发现冲突,记下第几组,找到最后一组没有找到和前面一样的输出-1。

*可以采用一个标记数组,就变得很简单了。

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
#include<stdio.h>
#include<string.h>
int main()
{int p,n;while(scanf("%d%d",&p,&n)!=EOF){int i;int x[305];int t;int tag=1;int temp;int w[304];//标记数组memset(w,0,sizeof(w));for(i=0;i<n;i++)scanf("%d",&x[i]);for(i=0;i<n;i++){t=x[i]%p;if(w[t]==0)w[t]=1;//进行标记else{tag=0;temp=i;break;}}if(tag==0)printf("%d\n",temp+1);elseprintf("-1\n");}return 0;
}

Codeforces Round #FF (Div. 2) A.DYZ Loves Hash相关推荐

  1. Codeforces Round #FF (Div. 2) B.DYZ Loves Strings

    *思路为对26个字母的价值进行排序,找到最大的价值,加最大的价值的字母往后放,价值最大. B. DZY Loves Strings time limit per test 1 second memor ...

  2. Codeforces Round #FF (Div. 2)C.DYZ Loves Sequence

    一道类似求严格递增子序列的题目.这道题可以改变一个数成任意数,使得严格递增子序列增加. *思路:两个标记数组from[i],to[i];from[i]的含义是从i出发的最长的严格递增序列长度,to[i ...

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

    原题链接:http://codeforces.com/problemset/problem/446/A 题意:给一个长度为n的序列,最多可以修改一个位置的数,求最长连续上升子序列. 题解:当a[i+1 ...

  4. Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列

    链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...

  5. Codeforces Round FF(Div. 2)

    layout: post title: Codeforces Round FF(Div. 2) author: "luowentaoaa" catalog: true tags: ...

  6. Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索

    Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec  Memory Limit: 512 MB Submit: xxx  ...

  7. Codeforces Round #453 (Div. 1) D. Weighting a Tree 构造 + dfs树

    传送门 文章目录 题意: 思路: 题意: 给你一颗nnn个点的图,每个点都有一个点权cic_ici​,要求你给每个边赋一个权值kik_iki​,要求对于每个点与他相连的边的权值之和等于这个点的点权ci ...

  8. Codeforces Round #722 (Div. 2)

    Codeforces Round #722 (Div. 2) 题号 题目 知识点 A Eshag Loves Big Arrays(题解略) 贪心 B Sifid and Strange Subseq ...

  9. Codeforces Round #756 (Div. 3)

    Codeforces Round #756 (Div. 3) A. Make Even 思路:如果末尾是偶数,不需要操作:如果开头是偶数,一次操作,即全翻转:如果开头和末尾都是 奇数,判断里面是否有偶 ...

最新文章

  1. Python 之 Numpy (四)索引
  2. 【RecyclerView】 一、RecyclerView 最基本用法 ( 添加支持库 | 设置布局文件 | 自定义适配器 )
  3. 纲:散户炒股存两大弱势 我自己不炒也不建议小散炒
  4. Android jdbc连接mysql报错解决方案 (Communications link failure)
  5. vue的使用(引用/创建vue项目)(一)
  6. jsp判断json第一位_java 判断字符串是否为json格式
  7. js(javascript)中__proto__和prototype解析
  8. GPU图形绘制管线简介
  9. (4329)Ping pong
  10. WEB免费打印控件推荐(4款)
  11. python3修改pip执行环境和安装软件源
  12. 大型强子对撞机再次遭遇断电
  13. @Value设置默认值
  14. 全方位移动全向轮、麦克纳姆轮底盘运动学逆解详解(内含电机输出方程)
  15. Vue——商品详情页(未完,写着以免忘掉)
  16. 百度网盘电脑登录二维码加载不出来解决方法
  17. html字体图标设置
  18. 斯坦福cs224n教程--- 学习笔记1
  19. 如何查看自己的分区是固态还是机械
  20. 杭电ACM 1713 相遇周期

热门文章

  1. 片袖原型制图_服装工艺八种袖子原型的制图画法
  2. 利用批处理bat批量处理word文档属性
  3. python基础知识测试题_Python中的单元测试—基础知识
  4. 黑客攻击常用cmd命令大全
  5. 劳务员培训建筑八大员培训建筑劳务企业分包的重要作用
  6. 如何用AI画出可爱的漫画少女插图?
  7. 十三种编程语言和它们名称背后的故事!
  8. 掌门教育余腾、吴佳峻,水滴公司邵文等登榜2020胡润Under30s创业领袖
  9. python执行cmd subprocess持续_Python subprocess 使用的几个小问题
  10. 开心汽车将与海淘车合并:前者4年亏损2亿美元,股权变更或遇阻