CodeChef is a non-commercial competitive programming community
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
    • Challenge
    • Peer
  • COMPETE
    • February Long Contest
    • January CookOff
    • January Long Contest
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • 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
    • Contact Us
    • 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

arjundevane @ 1 Dec 2009 04:26 PM

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.

arjundevane @ 1 Dec 2009 04:32 PM

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

"None of these warehouses are

AutumnRose @ 1 Dec 2009 05:07 PM
"None of these warehouses are near the new highway." that means there wont be any house on the highway?

In the graph shown, optimum

akhil89 @ 1 Dec 2009 08:11 PM

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 @ 1 Dec 2009 09:03 PM

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_09 @ 1 Dec 2009 10:10 PM

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

thnx........

Would you please elaborate on

rahulakaneo @ 1 Dec 2009 10:10 PM

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_09 @ 1 Dec 2009 10:25 PM

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

plz xplain....

@rahul If you think there is

admin @ 1 Dec 2009 11:06 PM

@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

rahulakaneo @ 1 Dec 2009 11:10 PM

@ 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 :)

rahulakaneo @ 1 Dec 2009 11:18 PM

Oops ! Sorry ! I means WA :)

can i get value of P , i

gunjanbansal @ 1 Dec 2009 11:36 PM

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

akhil89 @ 1 Dec 2009 11:38 PM

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

gunjanbansal @ 1 Dec 2009 11:38 PM

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

@Admin can we discuss upon

gunjanbansal @ 1 Dec 2009 11:41 PM

@Admin

can we discuss upon value of p here ?

Come on someone let out the

Saurabh Singh @ 2 Dec 2009 06:07 AM

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 @ 2 Dec 2009 06:09 AM

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

@saurabh @Gunjan No, please

admin @ 2 Dec 2009 04:38 PM

@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

codemax @ 2 Dec 2009 07:52 PM

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

sunillp @ 3 Dec 2009 12:27 AM

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

keedap @ 3 Dec 2009 10:39 PM

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

flying_ant @ 3 Dec 2009 11:03 PM

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

triplem @ 4 Dec 2009 01:58 AM

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

arun88m @ 4 Dec 2009 05:16 PM

Are the coordinates integers too?

Yes, please specify whether

vexorian @ 5 Dec 2009 07:54 PM

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

The problem statement

pieguy @ 6 Dec 2009 12:44 AM

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 ....

shanky89 @ 6 Dec 2009 05:42 PM

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

obviously they are not

notsoevil @ 6 Dec 2009 08:05 PM

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

avd122 @ 7 Dec 2009 05:20 PM

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

can anyone give a "-1"

Ctna @ 8 Dec 2009 06:13 PM

can anyone give a "-1" testcase ? thank

@Unni There cant be two

karthikm897 @ 9 Dec 2009 10:49 PM

@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

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com