Calculate the optimal position of the large pipeline

Assignment Help JAVA Programming
Reference no: EM13167304

• Oil company is planning a large pipeline from east to west (x-axis) across its oil field
• The field has n wells
• The company wants to connect each well directly to the large pipeline with smaller pipelines, running north-south (y-axis)

• Your task is to calculate the optimal position (on the y-axis) of the large pipeline, so that the total length of all smaller pipelines is shortest

• (If the large horizontal pipeline has the same y-coorindate as a well, length of smaller pipeline that is needed for that well is 0)

• You have the information about the positions of each well on the y-axis

110_Pipeline problem.png

• takes as input
• on the first Hne, the number of wells n, n>=2, n<1000000
• on each consecutive line (from 2nd to (n+1)-th line), the y-coordinate of one well (integers in the range 0 to 1000000000)
• returns on output
• a single number: the y-coordinate where the pipeline should be built (an integer in the range 0 to 1000000000)
• only this one number, no comments, prompts for input etc,
• Use Standard I/O to read input and write the result
• In Java, it's System.in for input, System.out for output
• Usage in Linux/MacOS:
> javac cmsc401.java
> cat someInput.txt lava cmsc401> result.txt
• Make sure the program compiles

Example of a correct result:

1099_Pipeline problem1.png

Length of connecting pipelines: 10. There are no y-positions for the large pipeline with total length of connecting pipelines smaller than 10. However, some other results also lead to 10.

Length of connecting pipelines: 7.

There is a better y-position, with the total length of connecting pipelines equal to 5.

100_Pipeline problem2.png

• OLJ should go through two phases:
• Abstract problem solving
• What is the general rule that leads to the solution
• Go through a couple of examples, try to come with a simple rule
• Algorithm design & coding
• Once you know what your solution is mathematically, think about howto find it quickly using an algorithm
• Threat the y-coordinates for n wells as an array A of the size n
• Design a divide & conquer method to solve the problem
• On Ar the algorithm should use Partition function from quicksort
• The whole structure should be recursive but different from quicksort
• Try to use the asymptotically fastest method possible B in terms of the expectedlaverage-case running time - aim at expected linea time
• slow methods vvill get lower score even if correct
• There may be several correct solutions that are equally good, return on output only one of them

Reference no: EM13167304

Questions Cloud

How will government regulation impact decision making : How will government regulation impact decision making and will the community's makeup be a consideration for decision makers?
What is the thickness\ : 1 oz of gold (density=19.3 g/ml) can be hammered into a sheet which would cover a 1.00 x 10^2 ft^2 area what is the thickness.
State the standard reaction enthalpy for the decomposition : The standard reaction enthalpy for the decomposition of CaCl2_NH3 into CaCl2 and NH3 is nearly constant at +78 kJ/mol between 350 K and 470 K.
What biochemical changes are required to convert tyrosine : What biochemical changes are required to convert tyrosine to (a) norepinephrine and (b) epinephrine? and 3- Some bacterial signaling systems involve kinases that transfer a phosphoryl group to a His side chain. Draw the phospho-His side chain.
Calculate the optimal position of the large pipeline : Your task is to calculate the optimal position (on the y-axis) of the large pipeline, so that the total length of all smaller pipelines is shortest
Unethical power : I have been exposed to unethical power and can tell you it is a very difficult situation to be involved in. However, sometimes we have to wonder if these situations are necessary to have these types of interactions to fortify our organizations and ou..
Define the reaction of a phenol and an anhydride : Asprin, whose structure can be found in the introduction, can be made from the reaction of a phenol and an anhydride. Give the phenol and anhydride that could be used to make aspirin?
Marie-elisabeth vigee-lebrun : What was the most notable achievement of Marie-Elisabeth Vigee-Lebrun?
Compute the theoretical yield of the complex : Assuming that all "other" reactants used in the synthesis of the complex are in excess, calculate the theoretical yield of the complex.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Method called printpowersof2 that accepts a maximum number

Write a method called printPowersOf2 that accepts a maximum number as an argument and prints each power of 2 from 20 (1) up to that maximum power, inclusive. For example, consider the following calls: printPowersOf2(3); printPowersOf2(10)

  Implement security so that all users can view the informatio

Implement security so that all users can view the information about the projects, but only authenticated users

  Wrappershallow and wrapperdeep

Each class is simply a wrapper class to hold a private array variable. int [] a; The default constructor for each class should initialize â??aâ??. Each class should have a toString() and equals(). Each class should have a setArray method that allows ..

  Implementation of memory management

Implementation of memory management

  Complete the twins() method

Complete the twins() method, which takes an integer argument n and prints all the sets of twin primes that are less than n, one pair per line

  Design and implement an applet called circles

Design and implement an applet called Circles that draws 50 circles of random diameter in random locations. If the diameter of a circle is less than a certain value, the circle is ?lled with the color yellow.

  Regular expression that selects lines

Write a regular expression that selects lines containing the html BR tag. The rules for this tag are that, like all html tags, it starts with . In between are the letters b and r in that order

  Modify the scholarship application

Modify the Scholarship application so that if a user enters a grade point average under 0 or over 4.0, or a negative value for either of the activities, an error message appears.

  Write a class to represent a credit card.

write a class to represent a credit card.

  A mini game made in java using zen graphics

a mini game made in Java using Zen graphics .

  Write java programming to show number of credits for course

Write the java programming to solve following problem. We are given a student's marks in Calculus 1, CS1, and Physics 1 (each mark being between 0 and 100) also number of credits for each course.

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

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