2
1
Fork 0

Day 5/C: Solve with a tree

This commit is contained in:
Mia Herkt 2021-12-05 18:26:38 +01:00
parent 406e1fc632
commit a980f49d42
Signed by: mia
GPG key ID: 72E154B8622EC191

25
05/solution_2_tree.c Normal file
View file

@ -0,0 +1,25 @@
#include <stdio.h>
#define O 1000
#define E(a,b,X)if(a==b){X}else
#define u int
#define C(x,y)m[x][y]++
#define P(a,b)a<b?1:-1
#define L(s,e)u S=P(s,e);for(u c=s;c!=e;c+=S)
int
main(
void){u m
[O][O]={0},x,
X,y,Y,I
=0;while(
fscanf(stdin,
"%i,%i -> %i,%i",&x
,&y,&X,&Y)==4){E(x,X,L(y,
Y)C(x,c);C(x,Y);)
E(y,Y,L(x,X)C(c,y);
C(X,y);){u h=x,v=y,H=P(
x,X),V=P(y,Y);for(;h!=X&&v!=Y
;h+=H,v+=V)C(h,v);C(h,v);};};for(y=
0;y<O;y++)for(x=0;x<O;x++)I
+=m[x][y]
>1;printf
("Answer: %d\n",I);;}