Page 2 of 4
Posted: Mon Sep 22, 2003 12:16 am
by bugzpodder
anything
wrong with these?
Input
Code: Select all
0 0 0 0 0
11 0 0 0 0
0.001 0
0 0.001
-0.001 0
0 -0.001
5 4
-10000 -10000
0 0
0 0
0 0
0 0
0 0
3 3 4 -10 0
-10000 -10000
0 0
3 4
3 3 4 -9.999 0
-10000 -10000
0 0
-390 -390
1 1.000 1.000 2.000 2.000
1.500 1.500
2 2.000 2.000 1.000 1.000
1.500 1.500
2.500 2.500
OUtput
Code: Select all
The gopher cannot escape.
The gopher can escape through the hole at (0.000,0.000).
The gopher can escape through the hole at (0.000,0.000).
The gopher cannot escape.
The gopher cannot escape.
The gopher can escape through the hole at (2.500,2.500).
Posted: Mon Sep 22, 2003 7:54 am
by junjieliang
Hi,
My output is almost the same as yours, but I have a space between the numbers (after the comma). Could that be your problem?
Code: Select all
My output
The gopher cannot escape.
The gopher can escape through the hole at (0.000, 0.000).
The gopher can escape through the hole at (0.000, 0.000).
The gopher cannot escape.
The gopher cannot escape.
The gopher can escape through the hole at (2.500, 2.500).
10310
Posted: Mon Sep 22, 2003 10:17 pm
by Sujoy Kumar Chowdhury
There should not be any space after the comma

Posted: Tue Sep 23, 2003 12:54 am
by bugzpodder
Thanks to Vassili I have fixed a precision error while reading the data.
10310 Dog and gopher WA
Posted: Mon Jun 14, 2004 4:03 pm
by nibbler
The following codes both get WA:
Code: Select all
#include <stdio.h>
long long dist(long long a,long long b,long long x,long long y) {
return (a-x)*(a-x)+(b-y)*(b-y);
}
int main()
{
double ddx,ddy,dgx,dgy,dx,dy;
long long ldx,ldy,lgx,lgy,lx,ly;
int N;
while (scanf ("%d %lf %lf %lf %lf",&N,&ddx,&ddy,&dgx,&dgy)==5) {
int escape=0;
ldx=(long long)(ddx*1000ULL);
ldy=(long long)(ddy*1000ULL);
lgx=(long long)(dgx*1000ULL);
lgy=(long long)(dgy*1000ULL);
for (int i=0;i<N;i++) {
scanf ("%lf %lf",&dx,&dy);
lx=(long long)(dx*1000ULL);
ly=(long long)(dy*1000ULL);
if (escape==0) {
if ( (4ULL*dist(ldx,ldy,lx,ly)) <= (dist(lgx,lgy,lx,ly)) ) {
printf ("The gopher can escape through the hole at (%.3lf,%.3lf).\n",dx,dy);
escape=1;
}
}
}
if (escape==0) printf ("The gopher cannot escape.\n");
}
return 0;
}
Code: Select all
#include <stdio.h>
double dist(double a,double b,double x,double y) {
return (a-x)*(a-x)+(b-y)*(b-y);
}
int main()
{
double dx1,dy1,dx2,dy2;
double dtx,dty;
int N,esc=0;
while (scanf ("%d %lf %lf %lf %lf",&N,&dx1,&dy1,&dx2,&dy2)==5) {
esc=0;
for (int i=0;i<N;i++) {
scanf ("%lf %lf",&dtx,&dty);
if (esc==0) {
if (4.0*dist(dx1,dy1,dtx,dty)<=dist(dx2,dy2,dtx,dty)) {
printf ("The gopher can escape through the hole at (%.3lf,%.3lf)\n",dtx,dty);
esc=1;
}
}
}
if (esc==0) printf ("The gopher cannot escape.\n");
}
return 0;
}
I just don't know where is the problem.
...
Posted: Tue Jun 15, 2004 12:52 pm
by sohel
I don't know about the first one, but your second code does not give the correct output for the sample....
Sample output
[c]
The gopher cannot escape.
The gopher can escape through the hole at (2.500,2.500).
[/c]
Your output
[c]
The gopher cannot escape.
The gopher can escape through the hole at (2.500,2.500)
[/c]
Can you see the difference...
.... "oh! yes I should add a period at the end of the second line."

10310 Please help me .......
Posted: Wed Jan 26, 2005 7:29 am
by J&Jewel
is this is a valid in c or c++
all are in double
r1=sqrt(pow(x1-h1,2.0)+pow(y1-o1,2.0));
Posted: Thu Jan 27, 2005 12:30 pm
by J&Jewel
can this ? correct for this problem..?
r1=sqrt(pow((x1-h1),2.0)+pow((y1-o1),2.0));
all in double.
10310
Posted: Sun Feb 06, 2005 1:16 am
by PerHagen
my code is but is wrong !!
#include <stdio.h>
#include <iostream.h>
#include <math.h>
void main (void){
double dg,dp,hx,hy,gx,gy,px,py,rhx,rhy;
int i,nhole;
while (scanf("%d %lf %lf %lf %lf",&nhole,&gx,&gy,&px,&py)==5){
int k=0;
for (i=1;i<=nhole;i++){
scanf("%lf %lf",&hx,&hy) ;
dg=sqrt( (hx-gx)*(hx-gx) + (hy-gy)*(hy-gy) );
dp=sqrt( (hx-px)*(hx-px) + (hy-py)*(hy-py) );
if(k==0){
if (2*dg<dp){
k=1;
rhx=hx;rhy=hy;
}
}
}
if (k==0) printf("The gopher cannot escape.\n\n");
else printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n\n"
,rhx,rhy);
}
}
help me
Posted: Tue Feb 08, 2005 1:01 am
by PerHagen
any answer please !!!
any I/O please
bytes!
Reply
Posted: Tue Feb 08, 2005 3:21 pm
by Raj Ariyan
The main problems with this type of problem is precission error. You used double,in my accepted code i used long double. But there are some other reason which led you wrong answer. Those are ....
1. Why u print two new lines every times ?
You write..
if (k==0) printf("The gopher cannot escape.\n\n");
else printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n\n"
,rhx,rhy);
u should print only one new line.
2. Again you write ...
if (2*dg<dp)
but it can be equal. So use...
if(2*dg==dp || 2*dg<dp)
May it helps you. Good luck.
Posted: Wed Feb 09, 2005 5:56 am
by sumankar
Floating point comparisons should be done with a little care in the form of some tolerance e.g. 1e-4,1e-6 ...etc.Read past threads for more info.
Regards,
Suman.
Posted: Thu Feb 10, 2005 7:47 pm
by PerHagen
thx
I got AC !!!
sorry ... but you have I/O of 507(jill again rides )
bytes!
Posted: Fri Feb 11, 2005 6:15 am
by sumankar
i/o?Sorry?
Quote sufficient material / write a tad bit more just to let us know who your intended audience is.
Regards,
Suman.
10310: vague problem statement
Posted: Mon Jan 16, 2006 10:42 pm
by shadow
The problem hasnt precisely defined the answer when the dog and the gopher both reach a hole at the same time. I think the answer in this case is "can reach".