The Best TowerProblem code: NX |
All submissions for this problem are available.
ByteTel, the largest mobile operator in Byteland, would like to find a place to construct a cellphone tower. There are N important places in Byteland that need to be considered.
These N buildings can be represented by N points in a 2D plane. The cellphone tower can be represented by a circle, and in order to construct the tower, ByteTel needs to specify its center and radius.
Moreover, the center of the tower cannot be outside the secure area, which is also a circle.
ByteTel wants to find a center and radius for the tower such that the total squared distance between each of the building and the tower is as small as possible.
The distance between a point and a circle is defined to be the difference between the distance from the circle's center to the point and the circle's radius.
Your task is to help ByteTel find a center and radius for their cellphone tower.
Input
The first line contains a number t (about 10), which is the number of test case. Each test case has the following form.
The first line contains three numbers (Xs, Ys) and Rs, specifying the secure circle.
The second line contains N, the number of buildings (1 N 100).
Each line in the next N lines contain two numbers which are the coordinates of a building.
All coordinates are integer and are between 0 and 10000 (inclusive).
Output
For each test case, output 3 numbers (X,Y) and R, rounded to 3 decimal digits, which are the center and radius of the cellphone tower.
Scoring
For each test case, your score is d/D in which:
d is the total square distance between each of the building and the tower your program has found
D is the total square distance between each of the building and the secure circle's center.
Your program's score is the sum of each test case's score, the lower the better.
Example
Input: 1 1 1 4 5 3 -2 2 1 5 3 4 3 4 -1 Output: 4.000 1.000 2.000
The sample output's score is 0.023444. The secure circle is red and the tower is yellow.

| Date: | 2010-02-05 |
| Time limit: | 6s |
| 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 |
Comments

Fetching successful submissions

Whats the constraint on
Whats the constraint on radius of tower?
I think the real question is,
I think the real question is, “What are the constraints on the coordinates?” My understanding is that -2 and -1 are not “between 0 and 10000 (inclusive)”.
@Manu It looks like there is no constraint, except that the tower cannot overlap any of the given buildings. This should be clarified though.
I believe that you need to
I believe that you need to parse
"The distance between a point and a circle is defined to be the difference between the distance from the circle's center to the point and the circle's radius."
as follows;
The distance ... is defined to be
[the difference between
{the distance from the circle's center to the point}
and {the circle's radius.}]
This seems to work for the example and places a constraint on the tower's radius.
I would like to see a
I would like to see a constraint on R as well. (Plus fixing the test case or constraints on input points.)
Actually, the question itself doesn't specify whether the tower can contain buildings. Which isn't necessarily a silly question, since a tower could easily be built above buildings. So I would like that clarified too.
Scoring seems to be broken
Scoring seems to be broken too. Everyone is getting 0 points.
do we have to print a new
do we have to print a new line after inputting number of test cases??
it doesnt say so in the problem statement but appears to be like that in the given example.
Please clarify. Thanks.
sorry, i'd like to reframe my
sorry, i'd like to reframe my previous query.
is there a new line to be read after we read the number of test cases T ??
it doesnt say so in the problem statement but appears to be like that in the given example.
Please clarify. Thanks.
Checking the issue related to
Checking the issue related to scoring. Internally it's working, it's being displayed as 0. So you may continue making submissions.
Checking the problem statement and constraints as well.
As a general point, the
As a general point, the submission system itself seems to be acting up - I seem to get internal error the first submission to a problem; every submission after that, I'm seeing the result of the *previous* submission. Had me very confused for a while..
The scoring issue is fixed.
The scoring issue is fixed. Please let me know if you are facing problems related to it.
@Stephen Will check this. The 'My Submissions' page still displays the correct results. You can check status on that page till this is resolved.
what is squared distance. is
what is squared distance. is it the square of distance?
IMPORTANT: @All R is between
IMPORTANT:
@All
R is between 0 and 10000 (inclusive) too
Now the 'my submissions'
Now the 'my submissions' scores are right but the scoreboard has everyone on 0 for this problem ;)
@Stephen. There is some issue
@Stephen. There is some issue with the DB which should be resolved soon.
still the score to this
still the score to this problem is showing zero
Sample output is not the best
Sample output is not the best tower that could be built, is it? Are you sure that there can be buildings inside tower?
Nobody said the sample output
Nobody said the sample output was optimal. This is a challenge problem; being optimal is not the point.
Slight wording
Slight wording problem:
"output 3 numbers (X,Y) and R, rounded to 3 decimal digits"
should be something like:
"output 3 numbers (X,Y) and R that have up to 3 decimal digits after the decimal point"
The first formulation says that the numbers I put in the output are not necessarily my actual answer, but an approximation of the answer. This means that the judge has no way of checking correctness, since it does not know the actual exact answer that might be correct while the rounded approximation isn't.
By the way - since we have no
By the way - since we have no test cases to verify solutions after the contest - I want to make sure that the checker actually verifies correctness exactly. That is, points on the secure circle are allowed, points even slightly outside the secure circle are rejected (using exact arithmetic), coordinates with more than 3 digits after decimal point are rejected.
@Tomek The numbers you put in
@Tomek The numbers you put in your output are your answer, by definition. I don't understand your comment.
What is total square
What is total square distance? Sum of squared distances or is it squared sum of distances?
@Brian I guess I wasn't
@Brian
I guess I wasn't clear. The problem is that the problem doesn't ask you to print X, Y, R. It asks you to print r(X), r(Y), r(R), where r(a) = a rounded to 3 decimal digits. But the constraints are on X,Y,R and not on r(X), r(Y), r(R). Therefore the judge has no way of verifying constraints or scoring, because it doesn't know what your X,Y,R are, since these are not in the output.
Example: suppose (Xs,Ys)=0, Rs=1. You find a valid tower (X,Y,R) = (0.9999, 0.001, 1). The output contains r(X), r(Y), r(R) = 1, 0.001, 1. The judge has no way of verifying whether X,Y lies inside the secure circle, because it only knows r(X), r(Y).
I don't think in this
I don't think in this problem, my output needs to be matched with expected output exactly.Then what is the meaning of getting "wrong answer" after submitting the solution?
Wrong answer means your
Wrong answer means your answer is not valid; which (unless you have done something like output a negative radius, or used the wrong input format) probably means your center is not within the secure circle.
my radius is positive ,input
my radius is positive ,input format is correct,center is with in the secure circle.What else the problems could be?
That's about it, other than
That's about it, other than perhaps not rounding answers to 3dp. Don't forget, as Tomek mentioned above, perhaps you think your point is in the secure circle, but after rounding to 3dp it isn't. Happened to me at one point.
@ dileep radius of tower
@ dileep radius of tower circle should also be less than 1000 as menioned by annirudh..
Can anybody explain me how
Can anybody explain me how the sample output's score 0.023444 has been calculated???
Thankx for ur suggestions
Thankx for ur suggestions ,and last problem ,is there any specific format for output,like now I am giving it with tab spaces (x{r} tab y{r} tab r} ,is it right?
@dileepkumar You simply have
@dileepkumar
You simply have to give one space between each x(r) ,y(r) and r
sample output
1.234 3.456 4.567
Thanx all for ur
Thanx all for ur suggesions,and my main problem is
In Dev c++ ,cout.precison(4),is giving 3 digits after decimal place,Got it corrected
The ranking is faulty. Those
The ranking is faulty.
Those who submitted 3 problems have been assigned the score of 4; seems Strange
How exactly the distance is
How exactly the distance is calculated between a point & a circle?
I don't understand what ot do with radius?
The distance between a point
The distance between a point and a circle in this problem is defined to be the absolute value of the difference between the radius of the circle and the distance from the point to the center of the circle. In other words, let D be the distance from the point to the center of the circle and R be the circle's radius. The distance from the point to the circle is now abs(D-R).
Did anybody verify that it's
Did anybody verify that it's impossible to do better than 1.563631? I used gradient descent (kinda), starting at a few different points, but there's no guarantee that my algorithm would always find the best possible solution.
My brute forcer gave the
My brute forcer gave the solution 1.563817 (very close to the best possible) :)
I think the test data for
I think the test data for this problem should be given out
hello, what is the optimal
hello,
what is the optimal solution for this problem? the simple n straightforward brute force comes close , though isnt the best 1.....
also, given a totally different input set, would all optimal solutions ( i.e. those that fetched 1.000000 pts) still give the same answer?
Given that you know the
Given that you know the center of the tower, you can easily prove that the optimal radius is the average distance from the center to each point. After that, any sort of hillclimbing algorithm will lead to the best center.
CodeChef submission 210202