Day 12: Add C solution
This commit is contained in:
parent
5c6f265376
commit
ba41403dfb
2 changed files with 60 additions and 0 deletions
20
12/input.txt
Normal file
20
12/input.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
VJ-nx
|
||||
start-sv
|
||||
nx-UL
|
||||
FN-nx
|
||||
FN-zl
|
||||
end-VJ
|
||||
sv-hi
|
||||
em-VJ
|
||||
start-hi
|
||||
sv-em
|
||||
end-zl
|
||||
zl-em
|
||||
hi-VJ
|
||||
FN-em
|
||||
start-VJ
|
||||
jx-FN
|
||||
zl-sv
|
||||
FN-sv
|
||||
FN-hi
|
||||
nx-end
|
40
12/solution.c
Normal file
40
12/solution.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
struct{
|
||||
#define K(a\
|
||||
,b) ((a&0x3f)\
|
||||
<<6|(b&0x3f))
|
||||
int n,e[8];}
|
||||
G [K('z',
|
||||
'z' )]={
|
||||
0} ; int p[
|
||||
64]={ 0},l=
|
||||
0;int R(int l,int
|
||||
D){ int C=0, c=p[l
|
||||
-1],N ,d, i=0,j
|
||||
;if(c ==1) return
|
||||
1; for( ;i
|
||||
<G[c].n; i++){N= G[c].e[i
|
||||
];d=0;if(N){ if((N&0x800)){for (j=0;j<l;j++
|
||||
)if(p[j]==N){d =1;break;}}if(!d||D){p [l]=N;C+=R(l+1
|
||||
,d ? 0:D);}}} return C;} int k( char*s){return
|
||||
(!strcmp(s,"" "star" "t" ))?0:( !strcmp(s,"e"
|
||||
"nd"))?1 :K(s[0]/* I HATE */,s[1]) ;}int
|
||||
main ()/* GRAPH THEORY */{ char
|
||||
a[8] ,b[8];while(scanf ("%7"
|
||||
"[^-]" "-%7"
|
||||
"s\n" ,a,b)
|
||||
==2){ int A
|
||||
=k(a) ,B=k
|
||||
(b);G [A].
|
||||
e[G[A ].n++
|
||||
]=B; G[
|
||||
B].e[G[B
|
||||
]. n++]=A;}
|
||||
printf("Silver"
|
||||
": %d Gold: %d"
|
||||
"\n",R(1,0),
|
||||
R(1,1));}
|
Loading…
Reference in a new issue