Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Problem Statement

Circles Country is a country that contains several circular-shaped districts. Some districts may be situated inside other districts, but their borders do not intersect or touch.

Qatam is a resident of Circles Country. When he travels between two locations, he always tries to cross the fewest number of district borders as possible because crossing borders is usually a laborious task.

Imagine Circles Country as an infinite plane. You are given int x[] and int y[] and int r[], where (x[i],y[i]) are the coordinates of the ith district's center and r[i] is its radius.

There are n circles altogether. Qatam is currently at point (x1,y1) and he needs to get to point (x2,y2).

Neither of these points lies on a district border. Return the minimal number of district borders he must cross to get to his destination.

Constraints

n will be between 1 and 50, inclusive.

x, y and r will each contain n elements.

Each element of x and y will be between -1000 and 1000, inclusive.

Each element of r will be between 1 and 1000, inclusive. x1, y1, x2 and y2 will be between -1000 and 1000, inclusive.

No two circumferences will have common points. The points (x1,y1) and (x2,y2) will not lie on any of the circumferences.

My Code: int least_borders(int x[], int y[], int r[], size_t n, int x1, int y1, int x2, int y2) { // fill in code here int borders = 0; int counter = 0; for (int i = 0 ; i < n; i++){ if (x1 < x[i]+r[i] && x1 > x[i]-r[i]){ if(y1 < y[i] + r[i] && y1 > y[i] - r[i]){ counter++; if (x1 < x[i]+r[i] && x1 > x[i]-r[i] && x2 < x[i]+r[i] && x2 > x[i]-r[i]){ if(y1 < y[i] + r[i] && y1 > y[i] - r[i] && y2 < y[i] + r[i] && y2 > y[i] - r[i]){ counter = counter - 1; } } } } if (x2 < x[i]+r[i] && x2 > x[i]-r[i]){ if(y2 < y[i] + r[i] && y2 > y[i] - r[i]){ counter++; if (x1 < x[i]+r[i] && x1 > x[i]-r[i] && x2 < x[i]+r[i] && x2 > x[i]-r[i]){ if(y1 < y[i] + r[i] && y1 > y[i] - r[i] && y2 < y[i] + r[i] && y2 > y[i] - r[i]){ counter = counter - 1; } } } } } borders = counter; return borders; }

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93092540

Have any Question?


Related Questions in Computer Engineering

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A chemistry student needsnbsp550 gnbspof dimethyl sulfoxide

A chemistry student needs 55.0 g of dimethyl sulfoxide for an experiment. By consulting the  CRC Handbook of Chemistry and Physics , the student discovers that the density of dimethyl sulfoxide is 1.10 g.cm^-3. Calculate ...

Question suppose the array begins with 0 followed by the

Question : Suppose the array begins with 0, followed by the remaining even integers in descending order, followed by the odd numbers in descending order. (For n = 8, the array would be [0,8,6,4,2,7,5,3,1].) How many comp ...

Question which register is allowed to be used as a pointer

Question : Which register Is allowed to be used as a pointer for register indirect addressing when accessing data stored in program ROM? Give the name and show how it is used Write a program that will read the following ...

Question suppose you have a 50-bit string that contains

Question : Suppose you have a 50-bit string that contains exactly 37 ones at random positions. How many bits of entropy does this string contain?

Is smartart graphic and table slide important for

Is Smartart graphic and Table slide important for PowerPoint Presentation? How would it benefit?

Task you want to calculate a students gpa for a number of

Task: You want to calculate a student's GPA for a number of classes taken by the student during a single semester. (In C# (C sharp)) Inputs: 1. the student's name 2. Class names for the classes taken by the student 3. Cl ...

Suppose a computer using set associative cache has 216

Suppose a computer using set associative cache has 2^16 words of main memory and a cache of 128 blocks, and each cache block contains 8 words. Show and type steps. Do not write please. a. If this cache is 2-way set assoc ...

Stuck in the mud is a popular dice game in uk the game uses

Stuck in the mud is a popular dice game in UK. The game uses five (5) 6-sided dice to play. The players play in turns. Choose one player to start the game. The player will roll all five (5) dice. If the player rolled any ...

This is sports data analysis with python classone way to

This is sports data analysis with python class. One way to judge a basketball lineup is to determine the point differential when that particular combination of players is in the game - in other words, how many points doe ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As