Imagine Circle 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 i-th district's center and r[i] is its radius. Zara is currently at point (x1,y1) and she needs to get to point (x2,y2). Neither of these points lies on a district border. Return the minimal number of district borders she must cross to get to her destination. Constraints x will contain between 1 and 50 elements, inclusive. x, y and r will each contain the same number of 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.
Imagine Circle 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 i-th district's center and r[i] is its radius. Zara is currently at point (x1,y1) and she needs to get to point (x2,y2). Neither of these points lies on a district border. Return the minimal number of district borders she must cross to get to her destination. Constraints x will contain between 1 and 50 elements, inclusive. x, y and r will each contain the same number of 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.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 3PE
Related questions
Question
Imagine Circle 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 i-th district's center and r[i] is its radius. Zara is currently at point (x1,y1) and she needs to get to point (x2,y2). Neither of these points lies on a district border. Return the minimal number of district borders she must cross to get to her destination.
Constraints
- x will contain between 1 and 50 elements, inclusive.
- x, y and r will each contain the same number of 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.
![3. {1, -3,2,5, -4,12,12}
{1,-1,2,5,5, 1,1}
{8,1,2,1,1,1,2}
-5
1
12
1
Returns: 3
منظم
O](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F385eb8fb-6648-4df6-8047-4f830c46ad3b%2F84502462-3f7c-45d0-a14e-25e001d5e071%2Fplgwueb_processed.png&w=3840&q=75)
Transcribed Image Text:3. {1, -3,2,5, -4,12,12}
{1,-1,2,5,5, 1,1}
{8,1,2,1,1,1,2}
-5
1
12
1
Returns: 3
منظم
O
![Examples
1.
2.
{0}
{0}
{2}
-5
1
Returns: 0
{0, -6,6}
{0,1,2}
{2,2,2}
-5
1
TST
1
Returns: 2
o](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F385eb8fb-6648-4df6-8047-4f830c46ad3b%2F84502462-3f7c-45d0-a14e-25e001d5e071%2Fd1r5td_processed.png&w=3840&q=75)
Transcribed Image Text:Examples
1.
2.
{0}
{0}
{2}
-5
1
Returns: 0
{0, -6,6}
{0,1,2}
{2,2,2}
-5
1
TST
1
Returns: 2
o
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
How would this work if this code was given?
![45 00
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class CircleCountry {
// Returns true if point (x,y) is inside circle determined by cx, cy, and r
// and returns false otherwise
public boolean isInside(int x, int y, int cx, int cy, int r) {
// return the result of testing whether the square of the distance
// from (cx, cy) to (x,y) is less than the square of the radius
// fill this in
}
public int least Borders (int[] x, int[] y, int[] r, int x1, int y1, int x2, int y2) {
int crosses = 0;
// loop through all circles
for (int k=0; k < x.length; k+= 1) {
(x2,y2) is inside circle k
// if exactly one of (x1, y1) and
// (specified by x[k], y[k], and r[k]), then increment crosses
// fill this in
}
}
return crosses;](https://content.bartleby.com/qna-images/question/385eb8fb-6648-4df6-8047-4f830c46ad3b/ec380a77-b7b1-4299-ab73-d538ee57c3f8/rudus9f_thumbnail.png)
Transcribed Image Text:45 00
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class CircleCountry {
// Returns true if point (x,y) is inside circle determined by cx, cy, and r
// and returns false otherwise
public boolean isInside(int x, int y, int cx, int cy, int r) {
// return the result of testing whether the square of the distance
// from (cx, cy) to (x,y) is less than the square of the radius
// fill this in
}
public int least Borders (int[] x, int[] y, int[] r, int x1, int y1, int x2, int y2) {
int crosses = 0;
// loop through all circles
for (int k=0; k < x.length; k+= 1) {
(x2,y2) is inside circle k
// if exactly one of (x1, y1) and
// (specified by x[k], y[k], and r[k]), then increment crosses
// fill this in
}
}
return crosses;
Solution
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning