forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1323(AC).cpp
61 lines (53 loc) · 835 Bytes
/
POJ1323(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
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int f[1001];
int n, m;
int a[55];
int b[55];
int ub[55];
int res;
int main()
{
int i, j;
int tmp;
int ti;
ti = 0;
while(scanf("%d%d", &m, &n) == 2 && (m || n)){
++ti;
memset(f, 0, 1001 * sizeof(int));
for(i = 0; i < n; ++i){
scanf("%d", &tmp);
a[i] = tmp;
f[tmp] = 1;
}
j = 0;
for(i = n * m; i >= 1; --i){
if(!f[i]){
f[i] = 1;
b[j++] = i;
if(j == n){
break;
}
}
}
sort(a, a + n);
sort(b, b + n);
res = n;
memset(ub, 0, 55 * sizeof(int));
for(i = n - 1; i >= 0; --i){
for(j = 0; j < n; ++j){
if(!ub[j] && b[j] > a[i]){
ub[j] = 1;
--res;
break;
}
}
}
printf("Case %d: %d\n", ti, res);
}
return 0;
}