-
Notifications
You must be signed in to change notification settings - Fork 0
/
1145.cpp
65 lines (63 loc) · 1.45 KB
/
1145.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/10/18.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <set>
#include <deque>
using namespace std;
const int MAXN = 1e4+10;
int Msize,n,m;
bool isPrime(int n){
if(n<2) return false;
for(int i=2;i<=sqrt(n);++i){
if(n%i == 0) return false;
}
return true;
}
bool used[MAXN]={false};
int main(){
scanf("%d%d%d",&Msize,&n,&m);
while (isPrime(Msize) == false) Msize++;
vector<int> v(Msize);
int location,key;
for(int i=0;i<n;++i){
scanf("%d",&key);
bool flag = false;
for(int j=0;j<Msize;++j){
location = (key+ j*j) %Msize;
if(!used[location]){
flag = true;
used[location] = true;
v[location] = key;
break;
}
}
if(!flag) printf("%d cannot be inserted.\n",key);
}
int cnt = 0;
for(int i=0;i<m;++i){
scanf("%d",&key);
for(int step=0;step<=Msize;++step){
cnt++;
location = (key + step*step)%Msize;
if(used[location] == false) break;
if(v[location] == key) break;
}
}
printf("%.1f",1.0*cnt/m);
}