FZU 2144 Shooting Game(计算几何)

E - Shooting Game
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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)这个位置上,然后N个 蚊子有各自的起始点和移动方向,主人公可以在任意时间攻击,攻击的时候那些跟他距离不超过R的 蚊子就算被击中,问最多能击中多少个以及最少要攻击几次才能打中最多的蚊子。

思路:首先求出每一只蚊子进入R范围和离开R范围的时间,如果一只蚊子始终都不会经过R范围内,那么我们不需要管他,然后对于某一时刻会进入R范围内的蚊子而言,对它的离开时间进行排序,运用区间调度的方法求出最少攻击次数

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

//#pragma comment(linker, "/STACK:1024000000,1024000000")

#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second

typedef __int64  LL;
typedef pair<int, int> PII;

const int MAXN = 1e5 + 5;
const double eps = 1e-10;
const LL INF  = 0x3f3f3f3f;
int T;
LL N, R;
int cnt;
struct o {
    double l, r;
    bool operator < (const o &p) const {
        return r < p.r;
    }
} O[MAXN];
int sgn(double x, double y) {
    if(fabs(x- y) <= eps) return 0;
    return x < y ? -1 : 1;
}
void cal (LL ax, LL ay, LL az, LL dx, LL dy, LL dz) {
    LL a = dx * dx + dy * dy + dz * dz;
    LL b = 2LL * (ax * dx + ay * dy + az * dz);
    LL r = R * R;
    LL c = ax * ax + ay * ay + az * az - r;
    LL dt = b * b - 4LL * a * c;
    if (dt < 0) return;
    double t1 = (-b * 1. - sqrt (dt * 1.) ) / (2. * a);
    double t2 = (-b * 1. + sqrt (dt * 1.) ) / (2. * a);
    if (sgn(t2, 0) == -1) return;
    O[cnt].l = t1;
    O[cnt].r = t2;
    cnt ++;
}

int main() {
#ifndef ONLINE_JUDGE
   // FIN;
//    FOUT;
#endif // ONLINE_JUDGE
    int cas = 0;
    scanf ("%d", &T);
    LL ax, ay, az, dx, dy, dz;
    while (T --) {
        cnt = 0;
        scanf ("%I64d%I64d", &N, &R);
        for (int i = 0; i < N; i ++) {
            scanf ("%I64d%I64d%I64d%I64d%I64d%I64d", &ax, &ay, &az, &dx, &dy, &dz);
            cal (ax, ay, az, dx, dy, dz);
        }
        sort (O, O + cnt);
        int ans = 0;
        double t = -INF;
        for (int i = 0; i < cnt; i ++) {
            if (t < O[i].l) {
                ans ++;
                t = O[i].r;
            }
        }
        printf ("Case %d: %d %d\n", ++ cas, cnt, ans);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值