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. Define Custom Data Filter Using Pre-Query Trigger In Oracle Forms

    Oracle Forms is having its default records filter, which we can use through Enter Query mode to spec ...

  2. 处理类型(typedef,uisng,auto,decltype)

    一:类型别名是一个名字,它是某种类型的定价.有两种方法定义类型别名: 1.使用typedef关键字,如: typedef int *Int_Ptr Int_Ptr p=nullptr;   //Int ...

  3. 【GLSL教程】(五)卡通着色 【转】

    http://blog.csdn.net/racehorse/article/details/6641623 引言 卡通着色可能是最简单的非真实模式shader.它使用很少的颜色,通常是几种色调(to ...

  4. testNG配置dataSource多数据源

    spring的XML配置好之后,运行testNG还会出问题. 搞定代码如下: /** * 基于Spring的服务层测试超类 * * @author chief */ @ContextConfigura ...

  5. 转: scala语言的简单入门 (IBM develop)

    转: https://www.ibm.com/developerworks/cn/java/j-lo-funinscala2/

  6. Shiro学习(7)与Web整合

    Shiro提供了与Web集成的支持,其通过一个ShiroFilter入口来拦截须要安全控制的URL.然后进行对应的控制,ShiroFilter相似于如Strut2/SpringMVC这样的web框架的 ...

  7. javascript---》Fcuntion对象

    Function 对象的valueOf() 和 toString() 方法.返回函数的源代码,调试时有用 Function 对象的 length 属性返回函数期望的参数个数------>接受任意 ...

  8. 应用程序之TableView简单总结1

    UITableView的代理方法 修改Cell的状态 UITableView常见方法 一.UITableView的代理方法 #pragma mark 每一行的高度 - (CGFloat)tableVi ...

  9. java位移操作

    http://www.cnblogs.com/kanego/archive/2011/03/21/1990617.html     java位移符号解释和举例

  10. windows下使用Eclipse编译执行MapReduce程序 Hadoop2.6.0/Ubuntu

    一.环境介绍 宿主机:windows8 虚拟机:Ubuntu14.04 hadoop2.6伪分布:搭建教程http://blog.csdn.net/gamer_gyt/article/details/ ...