FZU - 2144 Shooting Game(贪心,区间覆盖问题变题)

来源:互联网 发布:javascript submit 编辑:程序博客网 时间:2024/05/22 03:52
Problem 2144 Shooting Game

Accept: 267    Submit: 1368
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game in the playground. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.) But as they don’t like using repellent while playing this kind of special (hentai) game, they really suffer a lot from the mosquito. So they decide to use antiaircraft gun to shoot the mosquito. You can assume that the playground is a kind of three-dimensional space and there are N mosquitoes in the playground. Each of them is a kind of point in the space which is doing the uniform linear motion. (匀速直线运动) Fat brother is standing at (0, 0, 0) and once he shoot, the mosquito who’s distance from Fat brother is no large than R will be shot down. You can assume that the area which Fat brother shoot is a kind of a sphere with radio R and the mosquito inside this sphere will be shot down. As Fat brother hate these mosquito very much, he wants to shoot as much mosquito as he can. But as we all know, it’s tired for a man to shoot even if he is really enjoying this. So in addition to that, Fat brother wants to shoot as less time as he can.

You can (have to) assume that Fat brother is strong enough and he don’t need to rest after shooting which means that can shoot at ANY TIME.

 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case starts with two integers N and R which describe above.

Then N lines follow, the ith line contains six integers ax, ay, az, dx, dy, dz. It means that at time 0, the ith mosquito is at (ax, ay, az) and it’s moving direction is (dx, dy, dz) which means that after time t this mosquito will be at (ax+dx*t, ay+dy*t, ax+dz*t). You can assume that dx*dx + dy*dy+ dz*dz > 0.

1 <= T <= 50, 1 <= N <= 100000, 1 <= R <= 1000000

-1000000 <= ax, ay, az <= 1000000

-100 <= dx, dy, dz <= 100

The range of each coordinate is [-10086, 10086]

 Output

For each case, output the case number first, then output two numbers A and B.

A is the number of mosquito Fat brother can shoot down.

B is the number of times Fat brother need to shoot.

 Sample Input

6
2 1
2 0 0 -1 0 0
-2 0 0 1 0 0
2 1
4 0 0 -1 0 0
-2 0 0 1 0 0
2 1
4 0 0 -1 0 0
1 0 0 1 0 0
2 1
1 1 1 1 1 1
-1 -1 -1 -1 -1 -1
1 1
0 0 0 1 0 0
3 1
-1 0 0 1 0 0
-2 0 0 1 0 0
4 0 0 -1 0 0

 Sample Output

Case 1: 2 1
Case 2: 2 1
Case 3: 2 2
Case 4: 0 0
Case 5: 1 1
Case 6: 3 2


在立体的空间上,有n只蚊子,给出蚊子的坐标,以及蚊子的移动方向(向量),每次防空炮(0,0,0)的攻击范围为半径为r的球体。问说人最多可以打几只蚊子,要打多少次

就是区间选点问题(区间覆盖问题)的变形,由蚊子的运动方程 (x+dx)^2+(y+dy)^2+(z+dz)^2=R*R 可以求得蚊子飞入和飞出攻击范围的时间,于是变成了一维的区间选点问题,

思路不是很复杂但还是卡了好久,首先坐标和向量设成double输入会超时,然后用整型的话是long long的,cin也会超时。还是经验不够啊。。

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;#define MAXN 100005struct Qujian{double t1, t2;}qj[MAXN];bool cmp(Qujian a, Qujian b){if (a.t2 < b.t2) return true;else return false;}int main(){long long casen;long long n;long long r;long long x, y, z;long long dx, dy, dz;long long a, b, c;long long beita;double t1, t2, temp;scanf("%I64d", &casen);for (long long cas = 1; cas <= casen; cas++){scanf("%I64d%I64d", &n, &r);long long jishu = 0;for (long long i = 0; i < n; i++){scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &x, &y, &z, &dx, &dy, &dz);a = dx*dx + dy*dy + dz*dz;b = 2 * (dx*x + dy*y + dz*z);c = x*x + y*y + z*z - r*r;beita = b*b - 4 * a*c;if (beita >= 0){t1 = (-b + sqrt(beita*1.0)) / (2.0 * a);t2 = (-b - sqrt(beita*1.0)) / (2.0 * a);if (t1 > t2){temp = t1;t1 = t2;t2 = temp;}if (t2 >= 0){if (t1 < 0) t1 = 0;qj[jishu].t1 = t1;qj[jishu].t2 = t2;jishu++;}}}sort(qj, qj + jishu, cmp);long long time = 0;double hou = -1;for (long long i = 0; i < jishu; i++){if (qj[i].t1>hou){hou = qj[i].t2;time++;}}printf("Case %I64d: %I64d %I64d\n", cas, jishu, time);}}




0 0
原创粉丝点击