Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

• 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

Java, Programming

  • Category:- Java
  • Reference No.:- M9746041
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in Java

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

  • 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