think on (one's) feet
To be able to think clearly in times of stress, especially when forming a solution to a pressing problem. Thank goodness you were able to think on your feet and find another way to stop the pipe from leaking. The whole basement would have flooded otherwise.
think on one's feet
Fig. to be able to speak and reason well while (standing and talking) in front of an audience, especially extemporaneously. She really thinks on her feet well. I am not able to think on my feet too well before a bunch of people.