[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 nnumbers, 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.
Example
10 5021534153
4
5 501234
-1
题目的意思是,按顺序给出几个数,判断从哪个操作开始,hash值有重复.
题目很水,模拟一下就好了.
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; int main(){ int n,m; scanf("%d%d",&m,&n); ; i<=n; i++){ int x; scanf("%d",&x); x%=m; ;} vis[x]=; } puts("-1"); ; }
[CodeForces - 447A] A - DZY Loves Hash的更多相关文章
- 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 ...
- CF A. DZY Loves Hash
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 444 C - DZY Loves Colors
C - DZY Loves Colors 思路: 分块,复杂度有点玄学,和普通分块不同的是在这个块被一次染色的时候暴力染整个块. 代码: #pragma GCC optimize(2) #pragma ...
- [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
E DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ...
- [CodeForces - 447D] D - DZY Loves Modification
D - DZY Loves Modification As we know, DZY loves playing games. One day DZY decided to play with a n ...
- [CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...
- [CodeForces - 447B] B - DZY Loves Strings
B - DZY Loves Strings DZY loves collecting special strings which only contain lowercase letters. For ...
- D - DZY Loves Hash CodeForces - 447A
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...
- 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 ...
随机推荐
- shell案例题
目录: 1.批量生成随机字符文件名案例 2.批量改名特殊案例 3.批量创建特殊要求用户案例 1.批量生成随机字符文件名案例(P359) (1).利用openssl命令来实现 #!/bin/bash # ...
- 一、python (int & str 的方法)
1.变量:命名与使用 #!/usr/bin/env/ python # -*- coding:utf-8 -*- name = 'liQM' 只能包含字母.数字或下划线: 第一个字符不能是数字: 简短 ...
- 51nod 1351 吃点心(贪心)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1351 题意: 思路: 要么先选low值大的,要么先选high值大的,分两 ...
- 关于git提示“warning: LF will be replaced by CRLF”终极解答
一.发现问题 windows平台下使用git add,git deploy 文件时经常出现“warning: LF will be replaced by CRLF” 的提示. 网上很多解决办法提到: ...
- django表单的Widgets
不要将Widget与表单的fields字段混淆.表单字段负责验证输入并直接在模板中使用.而Widget负责渲染网页上HTML表单的输入元素和提取提交的原始数据.widget是字段的一个内在属性,用于定 ...
- CoordinatorLayout实现的效果(标题栏效果)
一.效果 CoordinatorLayouy是一个能够协调子布局的容器布局. 使用引入: compile 'com.android.support:design:24.1.1' 常见的使用方法如下:1 ...
- axios写法
- kbengine学习2 创建项目
官方文档https://www.comblockengine.com/docs/1.0/get-started/createproject/ 1.kbe服务器端 1.1 复制出一个assets文件夹, ...
- vux的x-input的源码分析
<template> <div class="vux-x-input weui-cell" :class="{'weui-cell_warn': sho ...
- maven的安装以及问题
https://blog.csdn.net/machao0903/article/details/73368909https://www.cnblogs.com/jiejiecool/p/421885 ...