Chandrakanta

You must have watched "Chandrakanta" serial in your childhood days. There is nothing to worry about even if u missed it. Let me tell you the story. Chandrakanta is a very beautiful princess of a state ‘Naugadh’ and is madly in love with prince "Kunvar Singh" of a neighboring state ‘Vijaygadh’. But the problem is that the two states are enemies of each other. Chandrakanta has been put up in a hidden place so that she could not meet the prince.

The place is such that it contains many circles of fire (i.e. fire is on the circumference of these circles). Chandrakanta has got certain number of lifelines which she can use to cross boundary of any circle.

Imagine the place as an infinite plane. Chandrakanta is currently at position(x1, y1) and his prince at(x2, y2). Suppose you know the number of lifelines, N available with Chandrakanta and the centre and the radius of the circles in plane are given. Just predict whether Chandrakanta would meet her prince??

Input

Input consists of several test cases. First line of input consists of an integer n, the no. of circles. Program terminates if n is equal to 0. Next n lines consist of three integers x y and R, the centre coordinates and radius of circle Next line contains x1, y1 and x2, y2. Next line contains the no. of lifelines, m.

 

Output

Print on a separate line "YES" or "NO" whether Chandrakanta would meet prince?

 

Sample Input

3
0 0 2
-6 1 2
6 2 2
-5 1 5 1
2
7
1 1 8
-3 -1 1
2 2 2
5 5 1
-4 5 1
12 1 1
12 1 2
-5 1 12 1
2
0

 

Sample Output

YES
NO

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Text.RegularExpressions;

using System.Collections;

 

namespace ConsoleApplication1

{

    class Coordinate

    {

        public double x;

        public double y;

        public Coordinate(double x, double y)

        {

            this.x = x;

            this.y = y;

        }

    }

    class Circle

    {

        public double centerX;

        public double centerY;

        public double radius;

        public Circle(double x, double y, double r)

        {

            centerX = x;

            centerY = y;

            radius = r;

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Coordinate c = new Coordinate(-5, 1);

            Coordinate p = new Coordinate(12, 1);

            int lifeLinesAvailable = 2;

            int lifeLinesRequired = 0;

            Circle[] obstacle = new Circle[7];

            obstacle[0] = new Circle(1, 1, 8);

            obstacle[1] = new Circle(-3, -1, 1);

            obstacle[2] = new Circle(2, 2, 2);

            obstacle[3] = new Circle(5, 5, 1);

            obstacle[4] = new Circle(-4, 5, 1);

            obstacle[5] = new Circle(12, 1, 1);

            obstacle[6] = new Circle(12, 1, 2);

            

            for (int i = 0; i < obstacle.Length; i++)

            {

                Coordinate temp = new Coordinate(obstacle[i].centerX, obstacle[i].centerY);

                if ((GetDistance(c, temp) < obstacle[i].radius && GetDistance(p, temp) > obstacle[i].radius) || (GetDistance(c, temp) > obstacle[i].radius && GetDistance(p, temp) < obstacle[i].radius))

                {

                    lifeLinesRequired++;

                }

            }

            Console.WriteLine("Life Lines Available: " + lifeLinesAvailable);

            Console.WriteLine("Life Lines Required: " + lifeLinesRequired);

            if (lifeLinesRequired <= lifeLinesAvailable)

            {

                Console.WriteLine("YES");

            }

            else

            {

                Console.WriteLine("No");

            }

        }

        public static double GetDistance(Coordinate P, Coordinate Q)

        {

            return (Math.Sqrt(Math.Pow((P.x – Q.x), 2) + Math.Pow((P.y – Q.y),2)));

        }

    }

}

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s