2014
03-16

# 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:
1. The towers have different heights and therefore there are no problems associated with the magnetic disks interfering with each other.
2. A missile will deflect if it passes through the magnetic disk of a tower or even if it just touches its boundary.
3. A missile hitting a tower (landing exactly on its location) will deflect, even if the tower is not given any energy.
4. 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.

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.

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

1. 2
2. 0

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const double PI = 3.141;
const double eps = 1e-8;

int sgn(double x) {
return (x > eps) - (x < -eps);
}

struct Point {
double x, y;
bool operator < (const Point _p) const {
return x < _p.x;
}
} p[1005], c1, c2;

double T;

int main()
{
int n;
int kase = 1;
while(scanf("%d", &n) == 1) {
if(n == 0) break;
scanf("%lf%lf%lf%lf%lf", &c1.x, &c1.y, &c2.x, &c2.y, &T);
T /= PI;

double x, y;
for(int i=1; i<=n; i++) {
scanf("%lf%lf", &x, &y);
p[i].x = (x-c1.x)*(x-c1.x)+(y-c1.y)*(y-c1.y);
p[i].y = (x-c2.x)*(x-c2.x)+(y-c2.y)*(y-c2.y);
}
sort(p+1, p+n+1);

int cur, ans = 0;
p[0].x = 0;
for(int i=0; i<=n; i++) {
x = p[i].x;
y = T - x;
if(sgn(y) < 0) break;

cur = i;
for(int j=i+1; j<=n; j++) {
if(sgn(y - p[j].y) >= 0) cur ++;
//printf("##%lf %lf %d\n", y, p[j].y, sgn(y - p[j].y));
}
if(cur > ans) {
ans = cur;
}
}

printf("%d. %d\n", kase++, n - ans);
}
return 0;
}

1. 学算法中的数据结构学到一定程度会乐此不疲的，比如其中的2－3树，类似的红黑树，我甚至可以自己写个逻辑文件系统结构来。