-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1145.cpp
More file actions
65 lines (60 loc) · 1.2 KB
/
Copy path1145.cpp
File metadata and controls
65 lines (60 loc) · 1.2 KB
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
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 100;
int hash[maxn], len;
bool prime(int x)
{
if(x == 1) return false;
int up = (int)sqrt(x);
for(int i = 2; i <= up; i++){
if(x % i == 0) return false;
}
return true;
}
int insert(int x)
{
int n = 1, p = x;
for(; n <= len; n++) {
if(hash[p % len] == 0) {
hash[p % len] = x;
break;
}
p = x + n*n;
}
return n;
}
int query(int x)
{
int n = 1, p = x;
for(; n <= len; n++) {
if (hash[p % len] == x || hash[p % len] == 0) break;
p = x + n*n;
}
return n;
}
int main()
{
freopen("input.dat", "r", stdin);
int n, m, x;
scanf("%d%d%d", &len, &n, &m);
while(!prime(len)) len++;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
int cnt = insert(x);
if (cnt > len) {
printf("%d cannot be inserted.\n", x);
}
}
printf("len=%d\n", len);
double sum = 0;
for (int i = 0; i < m; i++) {
scanf("%d", &x);
int cnt = query(x);
printf("cnt=%d\n", cnt);
sum += cnt;
}
printf("%.1f", sum/m);
return 0;
}