10310 - Dog and Gopher

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

Post by bugzpodder » Mon Sep 22, 2003 12:16 am

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).


junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post by junjieliang » Mon Sep 22, 2003 7:54 am

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).

Sujoy Kumar Chowdhury
New poster
Posts: 2
Joined: Mon May 05, 2003 2:14 am
Location: Bangladesh
Contact:

10310

Post by Sujoy Kumar Chowdhury » Mon Sep 22, 2003 10:17 pm

There should not be any space after the comma :wink:
y%<U

bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

Post by bugzpodder » Tue Sep 23, 2003 12:54 am

Thanks to Vassili I have fixed a precision error while reading the data.

nibbler
New poster
Posts: 22
Joined: Fri Jun 04, 2004 10:30 pm

10310 Dog and gopher WA

Post by nibbler » Mon Jun 14, 2004 4:03 pm

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.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

...

Post by sohel » Tue Jun 15, 2004 12:52 pm

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."
:wink:

User avatar
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

10310 Please help me .......

Post by J&Jewel » Wed Jan 26, 2005 7:29 am

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));
I hate Wrong Answer!

User avatar
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

Post by J&Jewel » Thu Jan 27, 2005 12:30 pm

can this ? correct for this problem..?
r1=sqrt(pow((x1-h1),2.0)+pow((y1-o1),2.0));
all in double.
I hate Wrong Answer!

PerHagen
New poster
Posts: 23
Joined: Thu Oct 14, 2004 1:45 am
Location: lima

10310

Post by PerHagen » Sun Feb 06, 2005 1:16 am

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
hello !

PerHagen
New poster
Posts: 23
Joined: Thu Oct 14, 2004 1:45 am
Location: lima

Post by PerHagen » Tue Feb 08, 2005 1:01 am

any answer please !!!

any I/O please


bytes!
hello !

Raj Ariyan
Learning poster
Posts: 70
Joined: Sat Feb 05, 2005 9:38 am
Location: Gurukul

Reply

Post by Raj Ariyan » Tue Feb 08, 2005 3:21 pm

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.
Some Love Stories Live Forever ....

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar » Wed Feb 09, 2005 5:56 am

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.

PerHagen
New poster
Posts: 23
Joined: Thu Oct 14, 2004 1:45 am
Location: lima

Post by PerHagen » Thu Feb 10, 2005 7:47 pm

thx

I got AC !!!

sorry ... but you have I/O of 507(jill again rides )

bytes!
hello !

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar » Fri Feb 11, 2005 6:15 am

i/o?Sorry?

Quote sufficient material / write a tad bit more just to let us know who your intended audience is.

Regards,
Suman.

shadow
New poster
Posts: 3
Joined: Mon Jan 16, 2006 10:33 pm

10310: vague problem statement

Post by shadow » Mon Jan 16, 2006 10:42 pm

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".

Post Reply

Return to “Volume 103 (10300-10399)”