PDA

Click to See Complete Forum and Search --> : C++ Problem


Wynd
Oct 25th, 2001, 07:41 PM
A mad dog is at the southwest coner of a square garden on top of the garden wall. A man is at the center of the garden. The dog will nip the man if he catches him on the wall, otherwise he will leave the man alone. The dog runs π times as fast as the man. π ~ 3.14159265.

A. Show that the man cannot get out by running to N or C or any place between D and N or D and C.

B. Write a program to check points on the wall between N and C by taking 2-meter intervals and printing out 'ouch' of the dog can catch man, 'safe' if man gets out. N C
|-------------------|
| |
| |
| |
300 M | M |
| |
| |
| |
|-------------------|
DI don't really have any idea how to start, can someone please help me?

kedaman
Oct 26th, 2001, 03:17 AM
X is the point to run to
L=D-X
Safe = (L.X+L.Y)/pi > |M-X|

I'll be back later on. Have a lecture now.

kedaman
Oct 26th, 2001, 04:27 AM
Putting D in origo we have:
X={[0,0...300],[300,0...300],[0...300,0],[0...300,300]}
M=[150,150]

Safe = (X.x+X.y)/pi > |M-X|

also you can calculate N with

(N.x+N.y)/pi > |M-N|

by have N either on the north or east wall

jim mcnamara
Oct 26th, 2001, 04:48 AM
I like this one.

The minimum distance the dog must is to point N
That distance is 300m + (1/2) * 300m = 450m
The maximum distance the dog must run is to point C
That distance is 300m + 300m = 600m
Any point for N < - > C is N + increment * 2,

so in pseudocode:

// hypoteneuse works only from 302m onward -
// otherwise the manDistance is150m
for (N1 = 302;N1<=600;N1+=2){
manDistance = hypoteneuse of triangle;
dogDistance = 300 + N1;
if manDistance > (dogDistance * pi) printf("safe")
else printf("ouch");
}



The hypoteneuse c of this triangle is:
c^2 = (N1)^2 + (150)^2
or
c = sqrt( (N1)^2 + (150)^2 )

Wynd
Oct 26th, 2001, 06:34 PM
Thanks a lot you guys, you really helped :)