-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv05.c
63 lines (58 loc) · 1.17 KB
/
v05.c
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
#include <stdio.h>
#include <stdlib.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define NT 10001 /* maximum time */
#define MT 16
static int t; /* show length */
static int res[NT][301]; /* game status */
static int eval_input(FILE *fp)
{
if (fscanf(fp, "%d", &t) != 1)
return 1;
return 0;
}
static int eval_solution(FILE *fp)
{
int winner;
int i, j;
if (fscanf(fp, "%d", &winner) != 1)
return -1;
for (i = 1; i <= 300; i++)
res[0][i] = 0;
for (i = 1; i <= t; i++) {
int losing = 0;
for (j = 1; j <= 10 && i >= j; j++)
losing += !res[i - j][j + MT];
for (j = 1; j <= 300; j++) {
if (j <= 300 - MT && i >= j)
res[i][j] = (losing + !res[i - j][j + MT]) > 0;
else
res[i][j] = losing > 0;
}
}
if (res[t - 30][30 + MT] && winner == 2)
return 1;
if (!res[t - 30][30 + MT] && winner == 1)
return 1;
return 0;
}
int main(int argc, char *argv[])
{
FILE *ifp, *ofp;
int score;
if (argc < 3)
return 1;
ifp = fopen(argv[1], "r");
ofp = fopen(argv[2], "r");
if (!ifp || !ofp)
return 1;
if (eval_input(ifp))
return 1;
fclose(ifp);
score = eval_solution(ofp);
fclose(ofp);
if (score < 0)
return 1;
printf("%d\n", score);
return 0;
}