It's a complicated issue. It might help give a more specific answer if I knew a few more things:
What kind of dancing do you do?
How old are you?
Is confidence an issue only in dancing, or in other areas of your life also?
But here are a few general ideas:
Work hard. Practice as much as you can and know your routines so well you do them in your dreams! The more secure you are in knowing your dance, the easier it is to feel confident.
Your teacher's advice about thinking you are the best dancer on the floor works better for boys than for girls, in my opinion. As girls, we are taught not to be "stuck-up" or to think we are "better" than someone else. So, fo me, trying to think I'm the best tends to make me uncomfortable (plus I feel silly thinking that when I know it's not true). I do better thinking things like, "I've worked really hard, I know my stuff, and I deserve to do really well" or "This is a beuatiful dance and I really want to give the audience the pleasure of seeing it done well."
If trying to "be sexy" makes you more nervous, don't think of it like that. When you come right down to it, it's just moves, like any other dance step. You move your hip a certain way, etc., and it will come across as sexy. I find it easier to start with the moves, then when I can do them well, I realize, hey, this feels sexy!
Don't think about doing well in the comp. Think about dancing to the best of your ability. You don't have control over how you do in the comp. Too much depends on who else signs up for it, what the particular judges tend to emphasize in their juding, and so on. But you do have control over dancing the best you can. Focus on that.
When you start to have doubts about your dancing, shoo them out of your mind and think about something you like about your dancing, something you know you do well, or that you know looks good when you do it.
Good luck and have fun!