-
Notifications
You must be signed in to change notification settings - Fork 0
/
task16-clocks.c
82 lines (70 loc) · 1.23 KB
/
task16-clocks.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
ID: zltsang1
LANG: C
TASK: clocks
*/
#include <stdio.h>
#define pn 9
typedef struct clocks pnl;
struct clocks{
int c[pn];
};
#if 1 //ver5.0
int ok(const pnl a){
int i;
for(i=0;i<pn;i++){
if(a.c[i]!=12)return 0;
}
return 1;
}
pnl ops(pnl ob,char *a){
while(*a){
ob.c[*a-'A']=(ob.c[*a-'A']+3)%12;
if(!ob.c[*a-'A'])ob.c[*a-'A']=12;
a++;
}
return ob;
}
char opt[9][10]={"ABDE","ABC","BCEF","ADG","BDEFH","CFI","DEGH","GHI","EFHI"};
pnl opn(pnl ob,int a){
ob=ops(ob,opt[a]);
return ob;
}
#endif
#define val(x,i) ((x)>>((i)<<1)&3)
int better(int l,int r){//lack proof of correctness, iff the answer is unique
return 1;
}
main () {
FILE *fin = fopen ("clocks.in", "r");
FILE *fout = fopen ("clocks.out", "w");
int i,j,k,best=0x3ffff,sz,a;
long long seq;
pnl ap,tp;
for(i=0;i<3;i++){
fscanf(fin, "%d %d %d\n", ap.c+i*3,ap.c+1+i*3,ap.c+2+i*3);
}
for(i=0;i<0x3ffff;i++){
tp=ap;
for(j=0;j<9;j++){
for(k=0;k<val(i,j);k++){
tp=opn(tp,j);
}
}
if(ok(tp)){
if(better(i,best))best=i;
}
}
sz=0;
for(j=0;j<9;j++){
sz+=val(best,j);
}
a=0;
for(j=0;j<9;j++){
for(k=0;k<val(best,j);k++){
if(a<sz-1){fprintf(fout, "%d ",j+1);a++;}
else fprintf(fout, "%d\n",j+1);
}
}
exit (0);
}