CF447A 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.

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.

Examples
Input

Copy

10 5021534153

Output

Copy

4

Input

Copy

5 501234

Output

Copy

-1就是问hash是否存在冲突;用 map 去判重即可;当然开数组也没问题;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 20005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {ll x = 0;char c = getchar();bool f = false;while (!isdigit(c)) {if (c == '-') f = true;c = getchar();}while (isdigit(c)) {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f ? -x : x;
}ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {if (!b) {x = 1; y = 0; return a;}ans = exgcd(b, a%b, x, y);ll t = x; x = y; y = t - a / b * y;return ans;
}
*/int n, p;
int x[maxn];map<int, int>mp;
int main() {//ios::sync_with_stdio(0);cin >> p >> n;int pos = -1;for (int i = 1; i <= n; i++)cin >> x[i];for (int i = 1; i <= n; i++) {int tmp = x[i];if (!mp[tmp%p]) {mp[tmp%p] = 1;}else if (mp[tmp%p]) {pos = i; break;}}cout << pos << endl;return 0;
}

posted @ 2019-01-03 16:48 NKDEWSM 阅读(...) 评论(...) 编辑 收藏

CF447A DZY Loves Hash 模拟相关推荐

  1. CF 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 Round #FF (Div. 2) A.DYZ Loves Hash

    水题.题目大意为输入一个p,n,再输入n组数据,每组数据对p取余,当和前面相同时,发现冲突,记下第几组,找到最后一组没有找到和前面一样的输出-1. *可以采用一个标记数组,就变得很简单了. A. DZ ...

  3. Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

    參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...

  4. Codeforces 447C - DZY Loves Sequences

    447C - DZY Loves Sequences 思路:dp 代码: #include<bits/stdc++.h> using namespace std; #define ll l ...

  5. Codeforces 446C —— DZY Loves Fibonacci Numbers(线段树)

    题目:DZY Loves Fibonacci Numbers 题意比較简单,不解释了. 尽管官方的题解也是用线段树,但还利用了二次剩余. 可是我没有想到二次剩余,然后写了个感觉非常复杂度的线段树,还是 ...

  6. BZOJ 3309 DZY Loves Math

    3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...

  7. HDU 5646 DZY Loves Partition

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5646 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  8. 【BZOJ3512】DZY Loves Math IV(杜教筛)

    [BZOJ3512]DZY Loves Math IV(杜教筛) https://www.cnblogs.com/cjyyb/p/10165338.html

  9. Codeforces 446C. DZY Loves Fibonacci Numbers【斐波那契+线段树】

    C. DZY Loves Fibonacci Numbers [题目描述] 传送门 [题解] 我们可以知道斐波那契数列有两个性质: ∑i=1nFi=Fn+2−F2\sum_{i=1}^{n} F_i= ...

最新文章

  1. oracle 数据有引号,oracle插入字符串数据时字符串中有'单引号问题
  2. 图片底下配的文字叫什么_38岁孙俪越来越有女人味!穿短裙配性感黑丝美腿撩人,短发超美...
  3. ML大杂烩:**常见机器学习算法公式梳理
  4. VS 2005 安装一个的小问题
  5. leetcode403 青蛙过河
  6. java.io 相关tips
  7. 关于CSS兼容IE与Firefox要点分析
  8. C# socket编程TcpClient与TcpListener UdpClient
  9. android-腾讯街景已经百度街景对比
  10. 275. H指数 II
  11. python geopy 北斗导航_【Python】使用geopy由经纬度找地理信息
  12. mysql工作时间获取_mysql获取当前时间,及其相关操作
  13. linux_Flatpak
  14. oracle怎样修改口令,修改Oracle数据库sys口令
  15. matlab+字体设置大小,Matlab中如何修改字体的大小?
  16. linux双系统没有wifi,遇到了双系统中win下关闭了wifi,ubuntu中也无法启用的情况...
  17. 2018 BUPT Winter Training #3 Div.2
  18. LOJ6482. LJJ 爱数数
  19. 浏览器兼容性问题(WEB项目中页面)
  20. 用电脑发传真用无纸传真系统3GFAXorMYFAX

热门文章

  1. VS 2010错误提醒: 必需属性“VSInstallDir”缺失或为空 以及 error MSB8008
  2. Unity分屏显示效果
  3. echarts动态legend不变更
  4. Floyd是咋求图的最短路径?
  5. JavaWeb之JavaScript及应用
  6. C++编译错误提示 [Error] name lookup of 'i' changed for ISO 'for' scoping
  7. js连接蓝牙打印机打印一维码和二维码
  8. java写netcdf_[转]netcdf入门
  9. c语言txt播放器,c语言播放器更新版
  10. UVM--Sequencer和Sequence