forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1252(AC).cpp
92 lines (82 loc) · 1.43 KB
/
POJ1252(AC).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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
int comp(const void *a, const void *b)
{
return *(const int *)a - *(const int *)b;
}
int v[10];
int a[1000];
int c;
int main()
{
int case_count, case_no;
int sum;
int max_n;
int i, j;
int n;
queue<int> q;
int qc, nqc;
while(true){
if(scanf("%d", &case_count) != 1){
break;
}
for(case_no = 0; case_no < case_count; ++case_no){
for(i = 0; i < 6; ++i){
scanf("%d", &v[i]);
}
qsort(v, 6, sizeof(int), comp);
for(i = 0; i < 1000; ++i){
a[i] = 0;
}
while(!q.empty()){
q.pop();
}
qc = 0;
for(i = 0; i < 6; ++i){
if(a[v[i]] == 0){
a[v[i]] = 1;
}
q.push(v[i]);
++qc;
}
c = 2;
while(!q.empty()){
nqc = 0;
for(i = 0; i < qc; ++i){
n = q.front();
q.pop();
for(j = 0; j < 6; ++j){
if(n + v[j] > 0 && n + v[j] < 1000 && a[n + v[j]] == 0){
a[n + v[j]] = c;
q.push(n + v[j]);
++nqc;
}
if(n - v[j] > 0 && n - v[j] < 1000 && a[n - v[j]] == 0){
a[n - v[j]] = c;
q.push(n - v[j]);
++nqc;
}
}
}
qc = nqc;
++c;
}
sum = 0;
max_n = -1;
for(i = 1; i <= 100; ++i){
sum = sum + a[i];
if(a[i] > max_n){
max_n = a[i];
}
}
printf("%.2f %d\n", 1.0 * sum / 100, max_n);
}
}
return 0;
}