For prestige the best way to go is to chose an attacker with half CP of the first defender in the gym. Whether you choose just the first defender or go for the next ones will depend on what defenders are there and what CP they have. Say if you see a Kingler or Pidgeot in the first slot and Snorlax or Lapras up next you would probably want to just work on the first one... if there are several weaker defenders it makes sense to work on 2 or 3 in a row to optimize prestige gain. Don't worry if you don't get 1000 points from the first one, if you take out 3 you will still get good prestige.
As to enemy gyms - just pick your best team of attackers :)