标签:turn 使用 记录 std 冲突 ios tor names can
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
bool isPrime(int n){
if(n <= 1) return false;
int sqr = (int)sqrt(n);
for(int i = 2; i <= sqr; i++){
if(n % i == 0) return false;
}
return true;
}
int main(){
int m, n;
cin >> m >> n;
while(!isPrime(m)){
m++;
}
vector<int> v(n), hash(m);
for(int i = 0; i < n; i++){
scanf("%d", &v[i]);
int size = 0;
while(size < m){
if(hash[(v[i] + size * size) % m] != 0){
size++;
}else{
hash[(v[i] + size * size) % m] = 1;
v[i] = (v[i] + size * size) % m;
break;
}
}
if(size >= m) v[i] = -1;
}
for(int i = 0; i < n; i++){
if(i != 0) printf(" ");
if(v[i] != -1) printf("%d", v[i]);
else printf("-");
}
return 0;
}
A1078 Hashing (25分)(哈希表、平方探测法)
标签:turn 使用 记录 std 冲突 ios tor names can
原文地址:https://www.cnblogs.com/tsruixi/p/13216276.html