Reaching the RigProblem code: REACHRIG |
Oil excavation is a common phenomenon in the sea. At every excavation site a rig is setup to extract the oil. The only mode to reach a rig is by a boat. Men who would like to reach a rig use special purpose boats which can run on crude fuel available at the rigs and the shore. These boats can run a mile for every unit of fuel they consume. Each man on the boat consumes a unit of food for every mile he travels. Boats have a limited load capacity. The net weight, including the weight of fuel, food and the men, on boat should never exceed its load capacity. The weight of one unit of fuel is same as the weight of one unit of food. However, as the rigs are far from the shore in the sea it is usually a very long sail. The capacity of the boat available for fuel may not be sufficient to reach the destination rig directly. In such cases, the men may goto a near by rig to load required fuel. The men can also store food at the rigs as well as at the shore for later consumption. They must buy all the food they require to reach the destination rig at the shore only. And all the men who started should be together throughout the sail.
You should now write a program which can help these men decide the minimum amount of food they require to reach the destination rig. The positions of rigs and the boat's starting point are indicated as co-ordinates of a two dimensional plane with x and y axises of 1 mile units. Food at shore is available only in whole units.
Assume that the food and fuel are consumed continuously, that is if you travel a partial mile the number of units of food and fuel consumed is equal to portion of mile traveled..
Input
The first line contains the number of test cases (An integer <= 100).
Each test case comprises of multiple lines containing list of integers as described below.
The first line of a test case has a list of integers terminated by -1. The first integer is the capacity of the boat. The integers following it up to -1 are the weights of men who need to reach the destination rig.
Lines following will have two integers separated by a space, each line indicating the x and y coordinates of a coordinate pair respectively. The first co-ordinate pair indicates the position of the boat's starting point. The last coordinate pair indicates the position of the destination rigs. All other points indicate the position of various rigs in the sea in a random order. The input for this test case will be terminated by a coordinate pair (0,0) and this should not be processed.
Output
For each test case, your program should print the minimum amount of food required to reach the destination on a separate line. If it is not possible to reach destination, then the program should print -1.
Example
Input: 3 250 20 30 -1 10 -20 -10 5 30 15 15 35 0 0 300 15 20 30 -1 10 -20 -10 5 30 15 -30 45 0 0 150 20 30 -1 1 1 100 100 0 0 Output: 111 807 -1
| Author: | admin |
| Date Added: | 26-01-2010 |
| Time Limit: | 2 - 10 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, C, C99 strict, CAML, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, HASK, ICON, JAR, JAVA, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

I posted a few solutions to
I posted a few solutions to this problem. I am getting a runtime error. In the mysubmissions page, the tooltip shows runtime error(OTHER), while in the home page, the tooltip shows runtime error (SIGSEGV). It would be helpful if could determine the actual error. I have used the math library function pow(). Could that be a reason for error?
Is there an upper bound on
Is there an upper bound on the number of points/men in a test case? If yes, what is the upper bound?
Can the admin please confirm
Can the admin please confirm if solution to 2nd test case is indeed 807 ? If it is, then can you please review the question statement?
either the question is not
either the question is not clear or check the 2nd test case..
@ Anshul, Jaideep: The 2nd
@ Anshul, Jaideep: The 2nd case is perfectly all right as per the test case.
Can it be confirmed whether there is an upper bound on the number of points/men? Or should I design my code so that it can handle any number of points?
Hello All, I am confused over
Hello All,
I am confused over this statement in problem:
"The men can also store food at the rigs as well as at the shore for later consumption. They must buy all the food they require to reach the destination rig at the shore only."
If men need to buy all food at starting shore only then whats the point in hacing food available at rigs?
Or is it that I have understood it wrongly.
Please help.
Manish
The boat has a limited
The boat has a limited capacity. If you store some food at a rig then you can go back to the shore and fill the boat up again, then make use of the extra food at the rig later.
OK Stephen...u mean to say
OK Stephen...u mean to say that by 'store' it means storing not in boat but at rig itself....
Yes.
Yes.
Guys, I have one more
Guys,
I have one more doubt.
Is return trip also to be taken into consideration?If its so, then I think answers for first and second cases are not in line.Answer for first case seems to be for one sided trip only while answer for second case is for both sided?
Does anyone agree with me?
What about the initial amount
What about the initial amount of food and fuel? For example, in the first case the weight of the two men adds upto 50kg. So for the remaning 200kg can we automatically assume that there is 100 units of food and fuel each?
@Admin @Mahul
@Admin
@Mahul Bhattacharya,
You get 807 by doing 32 *3*2 <- 3 round trips, depositing 43*3 food at point (-10 5) , then another trip to point (-10,5) 32*3 + 6 food. Total food consumed is 32*7 + 6 + 43*3 = 807 but i think this is wrong.
You can't deposit 43 food in a round trip . You are forgetting the weight of fuel. The total food deposited at point (-10,5) is 11 for each roundtrip because you need to store 32 fuel in the boat at shore.
Can you please clarify ?
the output is
the output is correct.
http://discussed.codechef.com/showthread.php?p=3082#post3082
@navin p your outputs are
@admin can you please take a
@admin can you please take a look at my solution...i am getting WA. Is there anything wrong with the logic or is it just rounding off values issues? If possible, can you also provide a particular test case?