Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Peer
  • COMPETE
    • September Algorithm Challenge
    • August Cook-Off 02
    • August Algorithm Challenge
    • July Cook-Off 01
    • January Algorithm Challenge
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • About Directi
Home » Compete » December 2009 (Contest XI) » Plant Location

Plant Location

Problem code: K1

  • All Submissions

All submissions for this problem are available.

A new highway called Highway 1 has just been built in the Kingdom of Byteland. Ingoo, the largest CPU manufacturer in Byteland, would like to build a new chipset plant along the highway.

Ingoo currently has N warehouses in the kingdom. None of these warehouses are near the new highway. Chipsets manufactured from the new plant must be delivered to the warehouses. Thus, the further the distances from the new plant to the warehouses, the more the delivery cost Ingoo needs to bear.

Therefore, the CEO of Ingoo would like to find a place on Highway 1 to build the new plant in such a way that the total distance from the plant to all the warehouses is minimized.

You are visiting Byteland on December vacation and have decided to help Ingoo to locate the new plant!

Input

The first line contains T (about 20), the number of test cases. Then T test cases follow. Each test case has the following form:

The first line contains a number N (1 <= N <= 2000), the number of Ingoo's warehouses.

The second line contains three integers A, B, C which describe the line equation (Ax+By+C=0) of Highway 1 (|A|, |B|, |C| <= 5000).

The next N lines contains the coordinates (x, y) of the warehouses (|x|, |y| <= 5000).

You are guaranteed that A, B, C form a valid line equation (i.e. A and B are not both 0) and no warehouses lie on Highway 1.

Output

For each test case, print in a single line the minimum total distance between the new plant and all the warehouses, rounded to 6 decimal places. If there is no optimum distance, print "NO" instead.

Example

Input:
1
5
3 -5 -7	
1 3
-2 4
4 -7
7 6
3 3

Output:
26.232349

Output details

The line equation of Highway 1 is 3x-5x-7=0. Ingoo have 5 warehouses: A(1,3), B(-2,4), C(4,-7), D(7,6), and E(3,3). The optimum location of the new plant is P as shown in the figure below:


Date: 0000-00-00
Time limit: 3

s
Source limit: 50000
Languages: C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK TEXT JS


  • Submit

Comments

  • Login or Register to post a comment.

Um, I am getting minimum

Arjun Devane - 1st Dec,2009 16:26:50.

Um, I am getting minimum total distance less than given in example here. Am I wrong or the output shown here?? (26.xxxxxx), i am getting (22.xxxxxx).

 

Oh, sorry. It was my mistake.

Arjun Devane - 1st Dec,2009 16:32:36.

Oh, sorry. It was my mistake. The output shown here is correct.

"None of these warehouses are

Vu Thi Thu Huong - 1st Dec,2009 17:07:54.
"None of these warehouses are near the new highway." that means there wont be any house on the highway?

In the graph shown, optimum

Core2duo - 1st Dec,2009 20:11:57.

In the graph shown, optimum location of plant P does not have integer cordinates. Is it not necessary for point P to have integer coordinates?

Why am i not getting output

Saurabh Singh - 1st Dec,2009 21:03:18.

Why am i not getting output accuratly. I am getting 26.xxxxxx but not precisely this answer and i am damn sure my logic is correct. Is there a way to make more precise calculations.

plz xplain the case(s) when

gurpreet - 1st Dec,2009 22:10:20.

plz xplain the case(s) when the o/p will be NO

thnx........

Would you please elaborate on

Rahul Gulati - 1st Dec,2009 22:10:32.

Would you please elaborate on the line "If there is no optimum distance, print "NO" instead". At both the ends of the line, the distance tends to infinity. So there has to be at least one minima. How could there be no optimal distance ?

i m also unable to understand

gurpreet - 1st Dec,2009 22:25:09.

i m also unable to understand the same ...............

plz xplain....

@rahul If you think there is

Admin - 1st Dec,2009 23:06:28.

@rahul If you think there is always an answer, you won't have to print 'NO'. You may output the answer :)

@ Aniruddha : What I am

Rahul Gulati - 1st Dec,2009 23:10:58.

@ Aniruddha : What I am thinking of right now is that, my interpretation of the line "If there is no optimum distance, print "NO" instead" is incorrect :-) and this is the reason why I am constantly getting TLE.

Anyways, thanks for the reply.

Oops ! Sorry ! I means WA :)

Rahul Gulati - 1st Dec,2009 23:18:24.

Oops ! Sorry ! I means WA :)

can i get value of P , i

Gunjan - 1st Dec,2009 23:36:52.

can i get value of P , i think my algo is write as p is is very close to the given p. but ans is a bit different

Someone plz reply to what

Core2duo - 1st Dec,2009 23:38:10.

Someone plz reply to what Saurabh Singh has written. I am in a similar position.

I am getting 26.2XXXXX, but not exactly what the answer is given here.

Can someone atleast give the coordinates of P?

ans is a few start differing

Gunjan - 1st Dec,2009 23:38:28.

ans is a few start differing from 2nd decimal place :(

@Admin can we discuss upon

Gunjan - 1st Dec,2009 23:41:16.

@Admin

can we discuss upon value of p here ?

Come on someone let out the

Saurabh Singh - 2nd Dec,2009 06:07:18.

Come on someone let out the value of P for this example . We are not getting answer becoz of this only . When u can tell output , what could be the problem in letting value of P out ?

And why does this site keep forgetting my password ?

Core2Due and i stuck in same

Saurabh Singh - 2nd Dec,2009 06:09:13.

Core2Due and i stuck in same mess . My answer is  also 26.2XXXXX.

@saurabh @Gunjan No, please

Admin - 2nd Dec,2009 16:38:53.

@saurabh @Gunjan No, please don't discuss specific values related to the answer. You are expected to work them out yourself.

Hey about the 'NO' thingy, i

Unni - 2nd Dec,2009 19:52:31.

Hey about the 'NO' thingy,

i think you can have 2 points with the same sum of distances, so u cant have a defenite answer

Does, " rounded to 6 decimal

Sunil Patil - 3rd Dec,2009 00:27:01.

Does, " rounded to 6 decimal places" mean if the answer is x.yyyyy66 it should be printed as x.yyyyy7 and if answer is x.yyyyy64 it should be printed as x.yyyyy6

i am the third person having

Deepak Sharma - 3rd Dec,2009 22:39:21.

i am the third person having the same problem ....

my answer is not matching after 26.2XXXXX

..

well admin just a request ..

u have shown a sample output

it would be nice if u can supply the value of P for the sample output

will help us

thanks

Yes, it should be fine with

Anil Kishore - 3rd Dec,2009 23:03:41.

Yes, it should be fine with telling completely about the sample case, giving nothing more than the answer. ( point P and Tot.Distance ).

There is no need to be told

Stephen Merriman - 4th Dec,2009 01:58:34.

There is no need to be told the location of point P. The example is solely there so you can understand the problem; it is not meant to give you hints as to how to solve it.

Are the coordinates integers

Arun Saragadam - 4th Dec,2009 17:16:54.

Are the coordinates integers too?

Yes, please specify whether

Victor Hugo Soliz Kuncar - 5th Dec,2009 19:54:50.

Yes, please specify whether the coordinates are necessarily integer numbers or not.

The problem statement

David Stolp - 6th Dec,2009 00:44:36.

The problem statement precisely describes the possible locations of the plant.  Make no assumptions unless they are given to you explicitly.

running fine on my pc ....

Shashank Sharma - 6th Dec,2009 17:42:02.

running fine on my pc .... but giving runtime error here . ny help

obviously they are not

Rajat Kumar - 6th Dec,2009 20:05:11.

obviously they are not integers. and instead of asking others you could urself compute the coordinates. anyway  i have greatly reduced the range but still stuck on TLE

I am also getting 26.2XXXXX

Aditya - 7th Dec,2009 17:20:16.

I am also getting 26.2XXXXX different from given answer and hence WA. Is the problem with precision?

can anyone give a "-1"

Nguyen Canh Toan - 8th Dec,2009 18:13:18.

can anyone give a "-1" testcase ? thank

@Unni There cant be two

karthik - 9th Dec,2009 22:49:46.

@Unni

There cant be two points giving the same distance(optimum)

Moreover if there exists more than 1 point giving the same distance(optimum), The task is to print the distance(optimum) and since since all points produce the same there will be nothing wrong in printing that distance

Directi Go for Gold

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Fetching successful submissions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • feedback@codechef.com
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
Sponsors
The time now is: