Return the minimal number of district borders

Assignment Help Computer Engineering
Reference no: EM132105071

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; }

Reference no: EM132105071

Questions Cloud

Write some java code for simple operations on binary search : Write some Java code for simple operations on binary search trees where keys are integers.
Pounds of materials at a total cost : Waterway purchased and used 2600 pounds of materials at a total cost of $15210. Waterway's total material variance is
Determine the choice of direction for a particular problem : Identify and list all factors that determine the choice of direction for a particular problem.
Compare one company performance in different periods : A common size financial statement is a useful tool in performance evaluation because it enables the user to:
Return the minimal number of district borders : Circles Country is a country that contains several circular-shaped districts. Some districts may be situated inside other districts, but their borders
What is the payback period on project a : a. What is the payback period on Project A, B and C? b. Calculate the NPV for projects A, B, and C (oportunity cost of capital 12%)
What is a cost accounting system : What is a cost accounting system? Why is a cost accounting system important for a business?
Calculate the npv if the required rate of return : A new HVAC system will require an initial outlay of $16,500, but it will increase the firm's cash flows by $3,300 a year for each of the next 6 years.
Simulate a scheduler scheduling a set of jobs : Let a job be represented as an object. A job needs to store such things as its name, arrival time, and duration.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd