# 1.4.2 The Clocks 时钟 (IOI'94 - Day 2)

1.4.2 The Clocks 时钟 (IOI'94 - Day 2)

``` |-------|    |-------|    |-------|
|       |    |       |    |   |   |
|---O   |    |---O   |    |   O   |
|       |    |       |    |       |
|-------|    |-------|    |-------|
A            B            C
```
``` |-------|    |-------|    |-------|
|       |    |       |    |       |
|   O   |    |   O   |    |   O   |
|   |   |    |   |   |    |   |   |
|-------|    |-------|    |-------|
D            E            F
```
``` |-------|    |-------|    |-------|
|       |    |       |    |       |
|   O   |    |   O---|    |   O   |
|   |   |    |       |    |   |   |
|-------|    |-------|    |-------|
G            H            I
```

1                  ABDE
2                  ABC
3                 BCEF
5                BDEFH
6               CFI
7              DEGH
8              GHI
9              EFHI

``````9 9 12
6 6 6
6 3 6``````

``````4 5 8 9
``````

``````#include <stdio.h>

int time[10],ans[9],res[9],min;
int change[9][5]={{0,1,3,4},{0,1,2},{1,2,4,5},{0,3,6},{1,3,4,5,7},{2,5,8},{3,4,6,7},{6,7,8},{4,5,7,8}};
int len[9]={4,3,4,3,5,3,4,3,4};

void solve(int k){
int i,t;
if(k==9){
for(i=0;i<9;i++){
if(time[i])
return ;
}//全归零
t=0;
for(i=0;i<9;i++)
t+=res[i];
if(min==0 || t<min){
min=t;
for(i=0;i<9;i++)
ans[i]=res[i];
}
return ;
}
for(t=0;t<4;t++){
res[k]=t;
for(i=0;i<len[k];i++){
time[change[k][i]]+=3*t;
time[change[k][i]]%=12;
}
solve(k+1);
for(i=0;i<len[k];i++){
time[change[k][i]]+=9*t;
time[change[k][i]]%=12;
}
}
}
int main(){
while(scanf("%d",&time[0])!=EOF){
int i,j;
char *c;
for(i=1;i<9;i++){
scanf("%d",&time[i]);
time[i]%=12;
ans[i]=res[i]=0;
}
time[0]%=12;
min=0;
solve(0);
c="";
for(i=0;i<9;i++){
for(j=0;j<ans[i];j++){
printf("%s%d",c,i+1);
c=" ";
}
}
printf("\n");
}
return 0;
}``````

``````#include <stdio.h>

int time[10],ans[9],res[9],min;
int change[9][5]={{0,1,3,4},{0,1,2},{1,2,4,5},{0,3,6},{1,3,4,5,7},{2,5,8},{3,4,6,7},{6,7,8},{4,5,7,8}};
int len[9]={4,3,4,3,5,3,4,3,4};

void solve(int k){
int i,t;
if(k==9){
for(i=0;i<9;i++){
if(time[i])
return ;
}//全归零
t=0;
for(i=0;i<9;i++)
t+=res[i];
if(min==0 || t<min){
min=t;
for(i=0;i<9;i++)
ans[i]=res[i];
}
return ;
}
for(t=0;t<4;t++){
res[k]=t;
for(i=0;i<len[k];i++){
time[change[k][i]]+=3*t;
time[change[k][i]]%=12;
}
solve(k+1);
for(i=0;i<len[k];i++){
time[change[k][i]]+=9*t;
time[change[k][i]]%=12;
}
}
}
int main(){
while(scanf("%d",&time[0])!=EOF){
int i,j;
char *c;
for(i=1;i<9;i++){
scanf("%d",&time[i]);
time[i]%=12;
ans[i]=res[i]=0;
}
time[0]%=12;
min=0;
solve(0);
c="";
for(i=0;i<9;i++){
for(j=0;j<ans[i];j++){
printf("%s%d",c,i+1);
c=" ";
}
}
printf("\n");
}
return 0;
}``````