ANARC09F - Air Strike

General Gee is the commander of a military base. He has just received alarming news from one of his spies: the enemy’s preparing an air missile strike. The base contains two magnetic towers. When activated and given sufficient power, each of the magnetic towers creates a powerful horizontal magnetic disk. If any missile passes through this disk it deflects away from the base. Although those towers seem to be an excellent air defense method, there is a problem: The area of the disk generated by a tower is proportional to the amount of energy it receives. The base has enough power plants to generate a certain amount of energy, which has to be divided among those two towers. That means that the total area of the two disks generated from the towers should not exceed the total energy generated by the power plants. Fortunately, the spy was able to know the exact target co-ordinates of the incoming missiles and he reported them to General Gee. The General needs your help in distributing the energy on the two magnetic towers to minimize the number of missiles that will not get deflected by the magnetic towers and therefore will hit the base. You may assume the following:

  • The towers have different heights and therefore there are no problems associated with the magnetic disks interfering with each other.
  • A missile will deflect if it passes through the magnetic disk of a tower or even if it just touches its boundary.
  • A missile hitting a tower (landing exactly on its location) will deflect, even if the tower is not given any energy.
  • All incoming missiles will go down simultaneously at the exact instant; therefore, there will not be any time available to redistribute the energy amongst the two towers during the strike.


Input consists of several test cases. Each test case is specified on N +2 lines. The first line contains an integer (1 ≤ N ≤ 1, 000) representing the number of missiles. The second line contains 5 real numbers X1 , Y1 , X2 , Y2 and T : (X1 , Y1 ) is the coordinates of the first tower, (X2 , Y2 ) is the coordinates of the second tower and (0 ≤ T ) is the total amount of energy generated from the power plants (the total area of the two magnetic disks). Each line of the remaining N lines contains two real numbers representing the landing coordinates of a missile. The absolute value of all the given real numbers is less than or equal to 100 and may include a decimal point followed by up to 3 digits. Any two consecutive numbers on the same line are separated by one or more white-space characters. Zero or more blank lines may appear between test cases.
The last line of the input file is made of a single zero.


For each test case, print the following line:
k. M
Where k is the test case number (starting at one,) and M is the minimum number of missiles that will NOT be deflected in the best distribution of energy among the two towers. Use π = 3.141.


-3 0 3 0 40.833
-1 4
-2 2.5
1 2
5 2
-4 0
-3 -1
0 0   1 1 0
0 0
1 1

1. 2
2. 0

hide comments
Sayak Haldar: 2015-10-21 05:18:03

Last edit: 2015-10-21 06:05:43
darryl: 2011-07-06 07:29:01

I agree. Just AC without using any floating points.

:D: 2010-11-04 12:56:03

Again, it can be implemented so that precision will be absolute on all calculations and comparisons. I think that it's what the problem author intended and that's why there is such a low tolerance for errors.

Last edit: 2010-11-04 12:56:32
Shaka Shadows: 2010-09-26 19:32:31

Too much precision issues!!! I had to change my idea from an NlogN to an N^2 brute forcer just because of that :(.

Last edit: 2010-09-26 19:32:58
Ravi Kiran: 2010-08-26 17:03:59

My code worked with judge io on my machine but it gave wa here.
Got ac with a precision check of around 1e-13.

:D: 2010-05-03 11:17:15

Re: lot of precision issues!!!

Actually it can be implemented so that there aren't any precision issues ;)

Luke Pebody: 2010-05-03 11:17:15

No. it should be
1. 0
2. 2

Luke Pebody: 2010-05-03 11:17:15

Am I correct in saying that the response for
0 0 100 100 157.05
95 100
105 100
3 4
4 -3
0 0 100 100 157.04
95 100
105 100
3 4
4 -3

should be

.:: Pratik ::.: 2010-05-03 11:17:15

lot of precision issues!!!

Added by:Mohammad Kotb
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 OBJC SQLITE