POJ 2902 Intercepting Missiles

Intercepting Missiles
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 122   Accepted: 54

Description

Our country is under enemy's attack. Hostile bombers are going to fly towards the capital and destroy everything. To defend the capital, we have a number of missiles, ready to launch and hit the enemy's bombers, before they reach the capital. Unfortunately, there are passenger planes in the sky, which we do not want to hit by our missiles.

We have been able to gather useful information regarding enemy's bombers. While they taxi over our missile defense zone, bombers travel in a fixed altitude. All bombers fly with the same speed. The same applies to airplanes, and our missiles. We know the location of each bomber and each airplane at time zero. Our missiles are placed on the ground, and their locations are also known.

You should write a program, that given the information about the bombers, and the locations of passenger planes in the sky, determines the maximum number of bombers that can be successfully hit by our missiles. Then, we pray for the rest of bombers to explode by themselves!

To simplify your task, The following are assumed:
  • We consider a flat two-dimensional model of the earth. Thus, the y-coordinate of the airplanes, and attacking bombers, does not change during their movement over our defense zone.
  • Each defending missile can be fired, at time zero or afterwards.
  • The y-coordinate of bombers, and airplanes are distinct positive integers.
  • Each bomber or airplane, has unit length, while our missiles have no length.
  • If a missile hits, or just touches the edge of a target in the sky, our missile will explode, while the target keeps moving normally on its path for a while before it explodes. Assume that the hit bomber will explode after passing all defending missiles, i.e. after surpassing the x-coordinate of all our missiles. Note that during this time, it may be hit by other missiles.

Input

The input file contains multiple test cases. The first line of the input, contains t, the number of test cases that follow. Each of the following t blocks, describes a test case, and is preceded by a blank line.

The first line of each block contains three integers, m, n and k (0 ≤ m, n, k ≤ 300), which are the number of bombers, airplanes, and our missiles, respectively. The second line contains three integers, vm, vn, and vk (1 ≤ vm, vn, vk ≤ 10, 000), which are the respective velocity of bombers, airplanes and our missiles. Airplanes and enemy’s bombers, are assumed to move to the right, for simplicity, while our missile move upwards, without changing their x-coordinates.

Next come m lines, that each gives the x and y coordinate of the head of a bomber, at time zero. The planes in the sky, are described similarly, in the following n lines. The last line contains k integers, each being the x-coordinate of a defending missile which is ready to launch. The coordinates are all nonnegative integers less than 10, 000.

Output

For each test case, output one line showing the maximum number of hit bombers, without any airplane being hit. Follow the format of the sample.

Sample Input

1
2 1 3
1 1 1
0 100
1 99
2 50
100 200 300

Sample Output

Mission #1: 1 bomber(s) exploded

Source

Tehran 2005

 

 

#include <iostream> #include <algorithm> #define MAX_N 305 using namespace std; //记录bomber的有关信息 struct bomber { int x, y; int v; }bombers[MAX_N]; //有效bomber对于在bombers中的下标以及有效bomber的数量 int validIndex[MAX_N]; int validNum; //记录有所民航飞机的信息 struct plane { int x, y; }planes[MAX_N]; //记录所有导弹的信息 struct missle { int x, rnum; int rel[MAX_N]; }missles[MAX_N]; int bn, pn, mn, sb, sp, sm, caseN; //对导弹进行排序的比较函数,按照X轴递增排序 bool compare(const bomber &b1, const bomber &b2) { return b1.x <= b2.x; } //判断导弹m能否击中轰炸机b bool canHit(int b, int m) { if(missles[m].x <= bombers[b].x) return false; return (missles[m].x - bombers[b].x) * sm >= bombers[b].y * sb; } //判断b1,b2是否是等价bomber bool theSameBomber(int b1, int b2) { if(bombers[b1].y >= bombers[b2].y) return false; return (bombers[b1].x - bombers[b2].x) * sm == (bombers[b2].y - bombers[b1].y) * sb; } //判断导弹m在击中轰炸机b之前是否会击中民航客机p bool theSameBP(const bomber &b, const plane &p, const missle &m) { if(!(m.x >= b.x && m.x >= p.x && p.y < b.y)) return false; if((m.x - b.x) * sm < b.y * sb) return false; if((m.x - p.x) * sm < p.y * sp) return false; //导弹发射前,bomber飞行的时间 double ft = double(m.x - b.x) / sb - double(b.y) / sm; //导弹发射时,bomber与导弹的x轴距离 double s1 = m.x - b.x - ft * sb; //导弹发射时,bomber与导弹的y轴距离 double s2 = b.y; //导弹发射时,plane与导弹的x轴距离 double s3 = m.x - p.x - ft * sp; //导弹发射时,plane与导弹的y轴距离 double s4 = p.y; //plane是否会阻拦导弹攻击bomber if((__int64)s1 * sp * s4 != (__int64)s2 * sb * s3) return false; return true; } //匈牙利算法的相关参数 int pre[MAX_N]; bool v[MAX_N]; //找增广路径 bool can(int node) { for(int i = 0; i < missles[node].rnum; i++) { int to = missles[node].rel[i]; if(v[to]) continue; v[to] = true; if(pre[to] == -1 || can(pre[to])) { pre[to] = node; return true; } } return false; } int main() { int c = 0, i, j, k; scanf("%d", &caseN); for(c = 1; c <= caseN; c++) { //输入与初始化 scanf("%d%d%d", &bn, &pn, &mn); scanf("%d%d%d", &sb, &sp, &sm); for(j = 0; j < bn; j++) { scanf("%d%d", &bombers[j].x, &bombers[j].y); bombers[j].v = -1; } for(j = 0; j < pn; j++) scanf("%d%d", &planes[j].x, &planes[j].y); for(j = 0; j < mn; j++) { scanf("%d", &missles[j].x); missles[j].rnum = 0; } sort(bombers, bombers + bn, compare); validNum = 0; //合并等价bomber for(i = bn - 1; i >= 0; i--) { if(bombers[i].v == -1) { validIndex[validNum++] = i; bombers[i].v = i; } else continue; for(j = i - 1; j >= 0; j--) { if(bombers[j].v != -1) continue; if(theSameBomber(i, j)) bombers[j].v = i; } } //建图 for(k = 0; k < mn; k++) { for(j = 0; j < validNum; j++) { bool can = true; int index = validIndex[j]; if(!canHit(index, k)) continue; for(i = 0; i < pn; i++) { if(theSameBP(bombers[index], planes[i], missles[k])) { can = false; break; } } if(can) missles[k].rel[missles[k].rnum++] = j; } } //匈牙利算法 int countv = 0; for(i = 0; i < validNum; i++) pre[i] = -1; for(i = 0; i < mn; i++) { memset(v, 0, sizeof(v)); if(can(i)) countv++; } printf("Mission #%d: %d bomber(s) exploded/n", c, countv); } return 0; }  

你可能感兴趣的:(算法,struct,velocity,input,each,output)