One way would be to watch how much clock time has passed and make a last-minute decision if your time is about to run out. Options for this include checking the time periodically, or using either setitimer or alarm to interrupt your program after some amount of time.
The rough power of the contest machines isn't secret, so you could estimate based on that. And of course you even submit your bot and do some trial-and-error to determine how much work you can do without timing out.
Or you could also just make your algorithm so super-fast that you don't even need one second.