Think on one’s feet

To think or reason or plan while one is talking or doing something (usually this is done under pressure).

I had to think on my feet when the flood waters began to approach my house.