Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
1 second
256 megabytes
standard input
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.
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
题意就是找相等的数,输出第二个的位置,可是要是最先发现的。
#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 1005const 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);}
转载于:https://www.cnblogs.com/yxwkf/p/5267254.html
Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash相关推荐
- Codeforces Round FF(Div. 2)
layout: post title: Codeforces Round FF(Div. 2) author: "luowentaoaa" catalog: true tags: ...
- Codeforces Round #FF (Div. 2) A.DYZ Loves Hash
水题.题目大意为输入一个p,n,再输入n组数据,每组数据对p取余,当和前面相同时,发现冲突,记下第几组,找到最后一组没有找到和前面一样的输出-1. *可以采用一个标记数组,就变得很简单了. A. DZ ...
- Codeforces Round #FF (Div. 2)C.DYZ Loves Sequence
一道类似求严格递增子序列的题目.这道题可以改变一个数成任意数,使得严格递增子序列增加. *思路:两个标记数组from[i],to[i];from[i]的含义是从i出发的最长的严格递增序列长度,to[i ...
- Codeforces Round #FF (Div. 2) B.DYZ Loves Strings
*思路为对26个字母的价值进行排序,找到最大的价值,加最大的价值的字母往后放,价值最大. B. DZY Loves Strings time limit per test 1 second memor ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
原题链接:http://codeforces.com/problemset/problem/446/A 题意:给一个长度为n的序列,最多可以修改一个位置的数,求最长连续上升子序列. 题解:当a[i+1 ...
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
- This is not playing but duty as allies of justice, Nii-chan! - Not allies but justice itself, Onii ...
- Codeforces Round #770 (Div. 2) Problem B.Fortune Telling
题意: 给定两个数,Alice的数x, Bob的数 x + 3,和一个长度为n的数组a,x和x + 3都要和a的每一个数执行 "加法" 或 "异或" 两个操作的 ...
- Codeforces Round #372 (Div. 2), problem: (B) Complete the Word
水题,每次截取长度为26的字符串,然后直接进行修改就可以 然而本弱渣昨天wa看很久 include<bits/stdc++.h> using namespace std; int n,c; ...
最新文章
- Hibernate two table same id
- 项目管理生命周期各个阶段的文档
- 数据中心管理人员预计2018年发生的变化
- 简单python接口测试编写和django开发环境的搭建
- java布尔多少字节,在Java中将字节转换为长度为4的布尔数组
- 机器学习工程师岗位面试经历之游戏行业
- 【报告分享】2020年中国企业直播服务市场研究报告.pdf(附下载链接)
- iOS逆向之自动化重签名
- c语言从入门到精通真垃圾,从入门到精通的C语言(吐血量)
- NB5.5源代码分析之服务端生成
- windows下使用curl命令
- mysql 用户名 长度_一个 MySQL 用户名长度的坑
- 扫拖地机器人预留_扫地机器人需要注意几个点?拖扫组合受追捧!
- 分子对接(docking):蛋白质-蛋白质分子对接
- 新闻推荐数据集MIND介绍
- raise ValueError(“‘label‘ must be of length ‘x‘“)
- 中消协:多款邮箱、通讯、金融理财APP过度收集个人信息!
- 对w10进行系统软件测试,W10专业版电脑显卡故障检测软件的使用方法
- python求集合的子集和子集个数
- “索引”并不是万能药
热门文章
- java treemarker_Java TreeMaker類代碼示例
- Nginx源码编译及安装
- 如何理解和使用Java package包
- java.util.stream.IntStream
- c语言几个字符串排序,请教多个字符串排序(不用数组)
- php.ini添加的变量读取,php用ini_get获取php.ini里变量值的方法
- python程序实例讲解_Python语言程序设计基础(2)—— Python程序实例解析
- 7.4读写锁(ReadWriteLock)
- Spring源码之bean的加载(三)从bean中获取对象
- 【渝粤题库】 陕西师范大学 202331 证券投资学 作业(专升本)