A good idea just came to my mind.

Literal

Good idea [subject-が] just-now my [of-の] heart [to-に] came-to-mind.

A slightly different location: 心 ('heart, mind') rather than 頭 ('head'). ちょうど ('just, exactly') modifies the timing. 心に浮かぶ is idiomatic for 'occur to one's mind/heart' — using 心 ('heart, mind') rather than the more head-y 頭 marks the thought as emotional or intuitive rather than strictly intellectual.