The simplest solution is to carry a composite longbow (make it adaptive when you get the chance if you plan on becoming stronger), which generally has effect with a range as long as any monster's attack. The alternative for spellcasters is to bring long range attacks like pyrotechnics or fireball. This obviates the need to be able to win the game of keep-away, but sometimes, it isn't a very good solution, particularly if you are pretty lousy with a bow but amazing in melee, and the enemy is a master of archery or ranged magic. Another possibility is to make it so the enemy's type of attack doesn't work either. This is hard to predict, since enemies have a variety of types of attack, and it mostly only works on archery, which can be prevented by a well-placed wind wall or even just the ridiculous hard counter to archery, fickle winds.
The rest of this lesson will assume that you desperately need to engage an enemy in melee that wants to stay away from you, examining a variety of the ways that the enemy will try to keep you out of melee, as well as countermeasures you can take.
One of the first keep-aways you might come across is difficult terrain. While certain clerics don't mind it, difficult terrain can turn what would be a monster you can charge immediately into one that requires two full movements to reach, allowing the enemy to act twice without you getting any attacks. Fortunately, it's surprisingly cheap to deal with difficult terrain. Feather Step slippers eliminate difficult terrain and cost a measly 2000 gold, which is not so much a cost as a blocker for other items on your feet. Even easier is a 2 prestige (or 750 gold) wand of feather step, which grants the same ability to ignore difficult terrain 50 times for 10 minutes each time, while saving your feet. If you have some means of flying (and we'll talk about that next), then you can sometimes just fly over the difficult terrain.
The big keep-away that you're likely to encounter is flying enemies. Something like a squadron of harpy archers can really ruin your day. The best simple fall-back solution to get into melee is a potion of fly, but that does cost 2 prestige or 750 gold every time you need it. You can try to make the flying enemies fall, but that's usually difficult. One of the most reliable ways to do it is to make them unable to act somehow, such as dazing, which stops them from keeping themselves aloft. If you want to be able to fly possibly multiple times in the same adventure without blowing tons of prestige on it, winged boots for 16000 gold is your cheapest option. It's basically three potions of fly each day, but you don't have to take out the potion to use it. If you use these boots a little over 20 times, they've paid for themselves compared to the potions. There's more constant ways to fly, such as a flying carpet or wings of flying, but they tend to cost a lot more, and you usually don't need more than the winged boots provide. A high level spellcaster can just use overland flight, but sadly it's personal only. The problem with all of these flying options is that you do need to be practiced at flying if you want to ensure you can hover and take a full attack, so if you have a druid or a cleric, one thing to do is have them cast air walk on you. It lasts for at least an hour and obviates the need for aerial training.
One last way to get up to an annoying enemy that isn't flying bears mention for how awesome it is--telekinetic charge. When your friendly spellcaster casts this, you get a free attack and end up right next to your foe, ready to full attack it. And with the Reach Spell metamagic, you can telekinetically charge well over 100 feet away from the caster!
There are many other ways to efficiently close the distance with keep-away enemies than the ones I described today. Feel free to mention some of you own favorites here as well.