题解 | CattleBruisers-牛客假日团队赛9F题

F-Cattle Bruisers_牛客假日团队赛9

https://ac.nowcoder.com/acm/contest/1071/F

题目描述

Canmuu is out for revenge after being utterly defeated by Bessie in paintball and has challenged Bessie to a video game.
In this game, Bessie starts out at point (BX, BY) in the coordinate grid , and tries to escape, starting at time 0. She moves continuously at a velocity of (BVX, BVY) units/second . Thus, at time 1 she will be at point ; at time 1.5 she will be at .
Unfortunately, Canmuu has sent cattle bruisers to pursue Bessie. At time t=0, cattle bruiser i is at position with velocity units/second
Each cattle bruiser carries a 'proximity' weapon to fire at Bessie; the weapon can hurt Bessie when the cattle bruiser is no further than units from her.
Bessie has a shield to protect herself from these attacks. However, she does not want to waste any of her shield's power, so she would like to know the maximum number of cattle bruisers within firing range for any (potentially non-integer) time t >= 0.
In order to avoid precision errors with real numbers, it is guaranteed that the answer produced will be the same whether the attack range is decreased to R-0.0001 or increased to R+0.0001.

输入描述:

* Line 1: Six space-separated integers: N, R, BX, BY, BVX, and BVY
* Lines 2..N+1: Line i+1 contains four space-separated integers: Xi, Yi, VXi, and VYi

输出描述:

* Line 1: Print a single integer denoting the maximum number of cattle bruisers within attack range at any point in time.

示例1

输入
3 1 0 0 0 2
0 -3 0 4
1 2 -1 1
1 -2 2 -1
输出
2
说明
Bessie starts at point (0, 0) and is moving at 2 units per second in the (positive) y-direction. There are 3 cattle bruisers, the first of which starts at point (0, -3) and travels 4 units per second in the y-direction. The maximum distance for a cattle bruiser to be in range of Bessie is 1 unit.
At time 1.5, Bessie is at point (0, 3), and the three bruisers are at points (0, 3), (-0.5, 3.5), and (4, -3.5). The first two cattle bruisers are within 1 unit of Bessie, while the third will never be within 1 unit of Bessie, so 2 is the most achievable.

解答

观察到题目中和杀手都在动,所以考虑相对运动,以的位置作为原点,不动,只考虑杀手运动。让不动,直接杀手的位置和速度减去的即可。
考虑杀手攻击半径为,转化一下即进入以为圆心,为半径的圆,就可攻击到
所以我们只要求出每个杀手进入该圆与离开该圆的时间点即可。最后就可以对所以时间点进行排序,然后对整条时间线进行类似于扫描线的方法统计答案。
显然就是这样一张图:

求出直线与圆的交点即可.
设杀手起点为,速度为,设在tt时刻恰好在交点,那么:
化简得到一个一元二次方程:
解出来即可。(即程序里的)
注意判断均为0的情况。
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
using namespace std;
int n,r,top;
double bx,by,bvx,bvy,eps=1e-8,L,R;
struct node{
    double x,y,vx,vy;
}a[500005];
struct TM{
    double t;
    int s;
}b[500005];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch^48);ch=getchar();}
    return ret*ff;
}
inline void work(double A,double B,double C){//a*t*t+b*t+c=0
    if(fabs(A)<eps){
        if(C<=0) L=0,R=1e9;
        else L=R=-1;
        return;
    }
    double delta=B*B-4*A*C;
    if(delta<0){//一元二次方程判根 
        L=R=-1;
        return;
    }
    L=(-B-sqrt(delta))/(2*A);
    R=(-B+sqrt(delta))/(2*A);
    if(L<0) L=0;
    if(R<0) R=-1;
}
inline bool cmp(TM a,TM b){
    return a.t<b.t;
}
signed main(){
    n=read(),r=read();
    bx=read(),by=read(),bvx=read(),bvy=read();
    for(int i=1;i<=n;i++){
        a[i].x=read()-bx;
        a[i].y=read()-by;
        a[i].vx=read()-bvx;
        a[i].vy=read()-bvy;
    }
    for(int i=1;i<=n;i++){
        double ds=a[i].x*a[i].x+a[i].y*a[i].y-r*r;
        work(a[i].vx*a[i].vx+a[i].vy*a[i].vy,2*a[i].x*a[i].vx+2*a[i].y*a[i].vy,ds);
        if(R!=-1) b[++top]=(TM){L,1},b[++top]=(TM){R,-1};
    }
    sort(b+1,b+top+1,cmp);
    int sum=0,ans=0;
    for(int i=1;i<=top;i++){
        sum+=b[i].s;
        ans=max(ans,sum);
    }
    printf("%lld",ans);
    return 0;
}



来源: ιχγббб 
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 16:22
点赞 评论 收藏
分享
06-13 17:33
门头沟学院 Java
顺序不记了,大致顺序是这样的,有的相同知识点写分开了1.基本数据类型2.基本数据类型和包装类型的区别3.==和equals区别4.ArrayList与LinkedList区别5.hashmap底层原理,put操作时会发生什么6.说出几种树型数据结构7.B树和B+树区别8.jvm加载类机制9.线程池核心参数10.创建线程池的几种方式11.callable与runnable区别12.线程池怎么回收线程13.redis三剑客14.布隆过滤器原理,不要背八股,说说真正使用时遇到了问题没有(我说没有,不知道该怎么回答了)15.堆的内存结构16.自己在写项目时有没有遇见过oom,如何处理,不要背八股,根据真实经验,我说不会17.redis死锁怎么办,watchdog机制如何发现是否锁过期18.如何避免redis红锁19.一个表性别与年龄如何加索引20.自己的项目的QPS怎么测的,有没有真正遇到大数量表21.说一说泛型22.springboot自动装配原理23.springmvc与springboot区别24.aop使用过嘛?动态代理与静态代理区别25.spring循环依赖怎么解决26.你说用过es,es如何分片,怎么存的数据,1000万条数据怎么写入库中27.你说用limit,那么在数据量大之后,如何优化28.rabbitmq如何批次发送,批量读取,答了延迟队列和线程池,都不对29.计网知不知道smtp协议,不知道写了对不对,完全听懵了30.springcloud知道嘛?只是了解反问1.做什么的?短信服务,信息量能到千万级2.对我的建议,基础不错,但是不要只背八股,多去实际开发中理解。面试官人不错,虽然没露脸,但是中间会引导我回答问题,不会的也只是说对我要求没那么高。面完问我在济宁生活有没有困难,最快什么时候到,让人事给我聊薪资了。下午人事打电话,问我27届的会不会跑路,还在想办法如何使我不跑路,不想扣我薪资等。之后我再联系吧,还挺想去的😭,我真不跑路哥😢附一张河科大幽默大专图,科大就是大专罢了
查看30道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务