Results 1 to 5 of 5

Thread: C++ Problem

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    C++ Problem

    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.
    Code:
                   N           C
          |-------------------|
          |                   |
          |                   |
          |                   |
    300 M |        M          |
          |                   |
          |                   |
          |                   |
          |-------------------|
         D
    I don't really have any idea how to start, can someone please help me?
    Last edited by Wynd; Oct 25th, 2001 at 07:52 PM.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    jim mcnamara
    Guest
    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:
    Code:
    // 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 )

  5. #5

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Thanks a lot you guys, you really helped

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width