9 #define MAX 1000 // determined by wc on the input
11 typedef struct particle particle
;
26 main (int argc
, char **argv
)
29 int minvalue
= 999999;
31 while (scanf ("p=<%d,%d,%d>, v=<%d,%d,%d>, a=<%d,%d,%d>\n", &p
->px
, &p
->py
,
32 &p
->pz
, &p
->vx
, &p
->vy
, &p
->vz
, &p
->ax
, &p
->ay
, &p
->az
) == 9) {
33 int value
= abs (p
->ax
) + abs (p
->ay
) + abs (p
->az
);
34 if (value
< minvalue
) {
40 printf ("closest particle among %d is %d\n", (int) (p
- field
), minrow
);
46 for (i
= 0; i
< MAX
- 1; i
++) {
50 for (j
= i
+ 1; j
< MAX
; j
++)
51 if (!field
[j
].dead
&& field
[i
].px
== field
[j
].px
&&
52 field
[i
].py
== field
[j
].py
&& field
[i
].pz
== field
[j
].pz
)
53 dead
= field
[j
].dead
= true;
56 // move particles; keep iterating if position or velocity decreases
58 for (i
= 0; i
< MAX
; i
++) {
63 int oldp
= abs (p
->px
) + abs (p
->py
) + abs (p
->pz
);
64 int oldv
= abs (p
->vx
) + abs (p
->vy
) + abs (p
->vz
);
71 if (oldp
> abs (p
->px
) + abs (p
->py
) + abs (p
->pz
) ||
72 oldv
> abs (p
->vx
) + abs (p
->vy
) + abs (p
->vz
))
75 printf ("at time %d with %d particles\n", gen
, alive
);
78 printf ("all particles resolved\n");