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 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.
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 a single integer — the answer to the problem.
10 5
0
21
53
41
53
4
5 5
0
1
2
3
4
-1
注意数据范围p,m<=200。尽管输入的数据较大,刚開始自己mod1000000001,发现这不能有冲突了,而且还要标记下第一个发生冲突,以后的冲突能够忽略
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL int
#define inf 0x3f3f3f3f
using namespace std;
int ha[10002];
int bj;
int main()
{
LL n,m,i,j,k,l;
while(~scanf("%d%d",&n,&m))
{
bj=0;
memset(ha,0,sizeof(ha) );
for(i=1;i<=m;i++)
{
scanf("%d",&k);
k=k%n;//对当前的输入值的个数进行%
if(!ha[k])
{
ha[k]++;
}
else if(ha[k]!=0&&!bj )//仅仅取。符合条件的第一个<span id="transmark"></span>
{
bj=i;
}
}
if(!bj)
printf("-1\n");
else printf("%d\n",bj);
}
return 0;
}
Codeforces Round #FF (Div. 2) A. DZY Loves Hash的更多相关文章
- 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] + ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification
枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...
- Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树
http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] + Fibonacci[i-l ...
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...
随机推荐
- java随机生成汉字
public static void main(String[] args) { String str = null; int hs, ls; Random random = new Random() ...
- 【Linux】CentOS7上安装JDK 和卸载 JDK 【rpm命令的使用】
之前有过一篇在CentOS7上安装JDK的文章:http://www.cnblogs.com/sxdcgaq8080/p/7492426.html 在这里又说一次,是要使用rpm命令安装JDK的rpm ...
- Vue的常用指令v-if, v-for, v-show,v-else, v-bind, v-on
Vue.js的指令是以v-开头的,它们作用于HTML元素,指令提供了一些特殊的特性,将指令绑定在元素上时,指令会为绑定的目标元素添加一些特殊的行为,我们可以将指令看作特殊的HTML特性(attribu ...
- 排序算法的实现(冒泡,选择,插入 O(N*N)--理解方法实现
以前也看过很多排序算法的原理,每次都想自己实现一下,一直都再拖,现在着牛课网学习算法课程,希望自己能够坚持练习. //对于一个int数组,请编写一个选择冒泡算法,对数组元素排序. //给定一个int数 ...
- [Other] An Overview of Arrays and Memory
One integer takes 32bit in memory, 1 byte = 8bits, therefore one integer takes 4 bytes. Now let's as ...
- 服务器和java程序的桥梁--jdbc/hibernate
现实的应用程序都是用户通过可视化界面发出指令从而修改数据库.本篇文章以Oracle为例,模拟怎么通过java代码实现数据库的增删改查. 新建一个Java项目,要建好桥梁,首先要拷入驱动Jar包放在项目 ...
- Json,String,Map之间的转换
前提是String的格式是map或json类型的 String 转Json JSONObject jasonObject = JSONObject.fromObject(str); String 转 ...
- hdu 4630 No Pain No Game(线段树+离线操作)
No Pain No Game Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 64位windows2003 未在本地计算机上注册 microsoft.jet.oledb.4.0 提供程序
64位windows2003系统 使用 mdb数据库时候出现如下错误. 可能用office的一些比较旧的程序时候会这样. 未在本地计算机上注册 microsoft.jet.oledb.4.0 提供程序 ...
- PLSQL Developer设置及快捷键设置
1.登录后默认自动选中My Objects 默认情况下,PLSQL Developer登录后,Brower里会选择All objects,如果你登录的用户是dba,要展开tables目录,正常情况都需 ...