### Re: 10310 - Dog and Gopher

Posted:

**Sun Oct 31, 2010 1:34 am**I got TLE with my code.... Can someone help????

Code: Select all

```
#include<cmath>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int N, i, c = 0;
while(1)
{
if(c != 0) cout << endl;
cin >> N;
c++;
int res = 0;
float dogx, dogy, gopx, gopy, escapex, escapey;
float holex[N], holey[N];
cin >> gopx >> gopy >> dogx >> dogy;
for(i = 0; i < N; i++)
{
cin >> holex[i] >> holey[i];
if(res != 1)
{
float dogdis, gopdis;
dogdis = sqrt(pow((dogx - holex[i]), 2) + pow((dogy - holey[i]), 2));
gopdis = sqrt(pow((gopx - holex[i]), 2) + pow((gopy - holey[i]), 2));
if(dogdis >= (2 * gopdis))
{
res = 1;
escapex = holex[i];
escapey = holey[i];
}
}
}
if(res == 0) cout << "The gopher cannot escape." << endl;
else printf("The gopher can escape through the hole at (%.3f,%.3f).\n", escapex, escapey);
}
return 0;
}
```