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,获得的得分是这一行 ...
随机推荐
- C++之纯虚函数
1. 纯虚函数形式 class Parent { public: ; }; 代码中的func1就是纯虚函数,没有函数体,没有函数的具体实现,有virtual,在函数名后面带有“ = 0”形式: 2.对 ...
- Mongodb副本集+分片集群环境部署
前面详细介绍了mongodb的副本集和分片的原理,这里就不赘述了.下面记录Mongodb副本集+分片集群环境部署过程: MongoDB Sharding Cluster,需要三种角色: Shard S ...
- ASP.NET MVC学习---(二)EF文件结构
之前已经简单的介绍过ORM框架和EF 也了解了EF的种种优点 那么这个EF到底长啥样子都还没见过呢 别着急 接下来,科学教育频道--走近科学 带你走进EF的内心世界~ 那么接下来就是~ 等等等等... ...
- zabbix自动化监控之自动注册
自动注册与自动发现刚好相反,是zabbix agent主动联系zabbix server,最后由zabbix server将这些agent加到host里.活动的Zabbix agent可以自动注册到服 ...
- Elasticsearch教程(一),全程直播(小白级别)
ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为Apach ...
- TestNG+ReportNG+IDEA+Git+Jenkins+surefire持续集成数据驱动dubbo接口测试
一.pom.xml增加testng相关配置 <!--添加插件 关联testNg.xml--><plugin> <groupId>org.apache.maven.p ...
- Troubles in Building Android Source Code
Some Troubles or problems you may encounter while you setup the Android source code build environmen ...
- git学习——撤销操作
修改最后一次提交:--amend 在提交完成后发现漏掉了几个文件没有加进去,或者提交信息写错了.想要修改怎么办? 现在可以先把需要修改的信息进行修改如:git add 添加没有添加的文件,vim &l ...
- UVA10312- Expression Bracketing(Catalan + 递推)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=1253">题目链接 题意:给出一个序列,长 ...
- 设计模式之十八:桥接模式(Bridge)
桥接模式: 将抽象部分和它的实现部分相分离开来,以使它们能够单独地变化. UML图: 主要包含: Abstraction:定义了抽象部分的接口.操作一个实现部分对象的引用. RefinedAbstra ...